[meld] Fix some cases of iteration over BufferLines (closes	bgo#638314)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc: 
- Subject: [meld] Fix some cases of iteration over BufferLines (closes	bgo#638314)
- Date: Fri,  7 Jan 2011 21:32:38 +0000 (UTC)
commit 0e7cc5202895acbe5c23ca964e2962ea2d3cec2a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Tue Jan 4 19:00:15 2011 +1000
    Fix some cases of iteration over BufferLines (closes bgo#638314)
    
    __getitem__ should raise an IndexError if an item beyond the last index
    is requested. Previously we did not do this, because we expect requests
    beyond the last line; specifically requests for (last line + 1). This
    patch changes our behaviour to correctly raise an IndexError if the
    request is for anything past (last line + 1).
    
    This fixes some cases of infinite iteration, as __iter__ wants to see
    that IndexError.
 meld/filediff.py |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index 175241e..a7fea3d 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -115,6 +115,8 @@ class BufferLines(object):
         return lines
 
     def __getitem__(self, i):
+        if i > len(self):
+            raise IndexError
         line_start = get_iter_at_line_or_eof(self.buf, i)
         line_end = line_start.copy()
         if not line_end.ends_line():
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]