Skip to content

Commit a968691

Browse files
committed
gridspec.GridSpecBase.__getitem__ checks its index (original patch from Paul Ivanov)
svn path=/trunk/matplotlib/; revision=8888
1 parent 753bc56 commit a968691

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/matplotlib/gridspec.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def __getitem__(self, key):
145145
else:
146146
if k1 < 0:
147147
k1 += nrows
148+
if k1 >= nrows or k1 < 0 :
149+
raise IndexError("index out of range")
148150
row1, row2 = k1, k1+1
149151

150152

@@ -153,6 +155,8 @@ def __getitem__(self, key):
153155
else:
154156
if k2 < 0:
155157
k2 += ncols
158+
if k2 >= ncols or k2 < 0 :
159+
raise IndexError("index out of range")
156160
col1, col2 = k2, k2+1
157161

158162

@@ -167,6 +171,8 @@ def __getitem__(self, key):
167171
else:
168172
if key < 0:
169173
key += total
174+
if key >= total or key < 0 :
175+
raise IndexError("index out of range")
170176
num1, num2 = key, None
171177

172178

0 commit comments

Comments
 (0)