# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1241409843 25200
# Node ID c5564e2ceb3a4dcb7f286d8e8534597925273d15
# Parent  17459264955c500a241af52bebd2e01715a85359
trac 5972 --  segfault in degenerate matrix multiply

diff -r 17459264955c -r c5564e2ceb3a sage/matrix/matrix_rational_dense.pyx
--- a/sage/matrix/matrix_rational_dense.pyx	Thu Apr 30 22:41:02 2009 -0700
+++ b/sage/matrix/matrix_rational_dense.pyx	Sun May 03 21:04:03 2009 -0700
@@ -2453,9 +2453,19 @@
             sage: matrix(QQ,2,[1/5,-2/3,3/4,4/9])._multiply_pari(matrix(QQ,2,[1,2,3,4]))
             [  -9/5 -34/15]
             [ 25/12  59/18]
+
+        We verify that 0 rows or columns works::
+        
+            sage: x = matrix(QQ,2,0); y= matrix(QQ,0,2); x*y
+            [0 0]
+            [0 0]  
         """
         if self._ncols != right._nrows:
             raise ArithmeticError, "self must be a square matrix"
+        if not self._ncols*self._nrows or not right._ncols*right._nrows:
+            # pari doesn't work in case of 0 rows or columns
+            # This case is easy, since the answer must be the 0 matrix.
+            return self.matrix_space(self._nrows, right._ncols).zero_matrix()
         cdef PariInstance P = sage.libs.pari.gen.pari
         _sig_on
         cdef GEN M = gmul(pari_GEN(self), pari_GEN(right))
