[GRASS-dev] [GRASS GIS] #1311: DebCheck QA: Array index is out of bounds

GRASS GIS trac at osgeo.org
Tue Apr 16 19:42:21 PDT 2013


#1311: DebCheck QA: Array index is out of bounds
------------------------------+---------------------------------------------
 Reporter:  hamish            |       Owner:  grass-dev@…              
     Type:  defect            |      Status:  new                      
 Priority:  normal            |   Milestone:  6.4.3                    
Component:  Compiling         |     Version:  6.4.0                    
 Keywords:  r.flow, v.in.dwg  |    Platform:  Linux                    
      Cpu:  Unspecified       |  
------------------------------+---------------------------------------------
Changes (by hamish):

  * milestone:  6.4.2 => 6.4.3


Comment:

 v.in.dwg patch backported to relbr64 in r52908. (done)

 ---

 wrt r.flow, the offending code allowing array index of -1 is:

 mem.h:
 {{{
 #define get(l, row, col) \
     (parm.seg ? \
         (segment_get(l.seg, &v, row + l.row_offset, col + l.col_offset) <
 1 ? \
           (sprintf(string,"r.flow: cannot read segment file for
 %s",l.name),\
            G_fatal_error(string)) : \
          v) : \
         l.buf[row][col])

 #define put(l, row, col, w) \
     (parm.seg ? \
         (v = w, \
          segment_put(l.seg, &v, row + l.row_offset, col + l.col_offset) <
 1 ? \
           (sprintf(string,"r.flow: cannot write segment file for
 %s",l.name), \
            G_fatal_error(string)) : \
          0) : \
         (l.buf[row][col] = w))
 }}}


 precomp.c:
 {{{
 static void interpolate_border(void)
 {
     int i, r = region.rows, c = region.cols;

     for (i = 0; i < c; i++) {
         put(el, -1, i, get(el, 0, i) * 2 - get(el, 1, i));
         put(el, r, i, get(el, r - 1, i) * 2 - get(el, r - 2, i));
     }
     for (i = 0; i < r; i++) {
         put(el, i, -1, get(el, i, 0) * 2 - get(el, i, 1));
         put(el, i, c, get(el, i, c - 1) * 2 - get(el, i, c - 2));
     }
     put(el, -1, -1, 3 * get(el, 0, 0) - get(el, 0, 1) - get(el, 1, 0));
     put(el, -1, c,
         3 * get(el, 0, c - 1) - get(el, 0, c - 2) - get(el, 1, c - 1));
     put(el, r, -1,
         3 * get(el, r - 1, 0) - get(el, r - 2, 0) - get(el, r - 1, 1));
     put(el, r, c,
         3 * get(el, r - 1, c - 1) - get(el, r - 2, c - 1) - get(el, r - 1,
                                                                 c - 2));
 }
 }}}


 Hamish

-- 
Ticket URL: <https://trac.osgeo.org/grass/ticket/1311#comment:5>
GRASS GIS <http://grass.osgeo.org>



More information about the grass-dev mailing list