Skip to content

Commit ecbd7bf

Browse files
committed
add one check for matrix index
1 parent 9abcd14 commit ecbd7bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

cypari2/gen.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1522,14 +1522,17 @@ cdef class Gen(Gen_base):
15221522
if typ(self.g) != t_MAT:
15231523
raise TypeError("cannot index PARI type %s by tuple" % typ(self.g))
15241524

1525+
if len(n) != 2:
1526+
raise ValueError("matrix index must be [row, column]")
1527+
15251528
i, j = n
15261529

15271530
if i < 0 or i >= glength(gel(self.g, 1)):
15281531
raise IndexError("row i(=%s) must be between 0 and %s" % (i, self.nrows()-1))
15291532
if j < 0 or j >= glength(self.g):
15301533
raise IndexError("column j(=%s) must be between 0 and %s" % (j, self.ncols()-1))
15311534

1532-
self.cache((i,j), x)
1535+
self.cache((i, j), x)
15331536
xt = x.ref_target()
15341537
set_gcoeff(self.g, i+1, j+1, xt)
15351538
return

0 commit comments

Comments
 (0)