changeset 1069:44eeb81593b2 octave-forge

check for out of bounds in allocation
author aadler
date Mon, 13 Oct 2003 03:44:26 +0000
parents a9c30f62cb2e
children b32eecedb0c5
files main/sparse/sparse_ops.h
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/main/sparse/sparse_ops.h	Thu Oct 09 09:00:50 2003 +0000
+++ b/main/sparse/sparse_ops.h	Mon Oct 13 03:44:26 2003 +0000
@@ -19,6 +19,9 @@
 $Id$
 
 $Log$
+Revision 1.10  2003/10/13 03:44:26  aadler
+check for out of bounds in allocation
+
 Revision 1.9  2003/04/03 22:06:41  aadler
 sparse create bug - need to use heap for large temp vars
 
@@ -277,9 +280,11 @@
    OCTAVE_QUIT; \
    for (int i=0; i<nnz; i++) { \
       if ( coefA(i) != 0. || cf_scalar ) { \
-         sidx[actual_nnz].val = (long) ( \
-                   ( ri_scalar ? ridxA(0) : ridxA(i) ) - 1 + \
-              m * (( ci_scalar ? cidxA(0) : cidxA(i) ) - 1) );  \
+         double rowidx=  ( ri_scalar ? ridxA(0) : ridxA(i) ) - 1; \
+         if (rowidx >= m) SP_FATAL_ERR("sparse: row index out of range"); \
+         double colidx=  ( ci_scalar ? cidxA(0) : cidxA(i) ) - 1;  \
+         if (colidx >= n) SP_FATAL_ERR("sparse: col index out of range"); \
+         sidx[actual_nnz].val = (long) ( rowidx + m*colidx ); \
          sidx[actual_nnz].idx = i; \
          actual_nnz++; \
       } \