[GRASS-dev] Re: [GRASS GIS] #775: r.terraflow: file=/home/mlennert/STREAM/STREAM_tQhXkQ:cannot read!: Bad address

GRASS GIS trac at osgeo.org
Sat Oct 10 05:41:22 EDT 2009


#775: r.terraflow: file=/home/mlennert/STREAM/STREAM_tQhXkQ:cannot read!: Bad
address
-----------------------+----------------------------------------------------
  Reporter:  mlennert  |       Owner:  grass-dev at lists.osgeo.org
      Type:  defect    |      Status:  new                      
  Priority:  normal    |   Milestone:  6.4.0                    
 Component:  Raster    |     Version:  svn-develbranch6         
Resolution:            |    Keywords:  terraflow bad address    
  Platform:  Linux     |         Cpu:  Unspecified              
-----------------------+----------------------------------------------------
Comment (by glynn):

 Replying to [comment:5 mlennert]:

 > > so the assert() shouldn't be triggering. But that may just be an
 artifact of optimisation. Can you reproduce this if libiostream and
 r.terraflow are built without optimisation?
 >
 > Now I get err = AMI_ERROR_IO_ERROR.

 Well, the immediate issue is that fread() is returning a short count but
 not setting the end-of-file indicator.

 The short count is to be expected: it's trying to read run_size = 13027967
 items although it only expects there to be last_run_size = 38343 items in
 the file (and has only allocated enough memory for that many).

 Given the "Bad address" from perror(), my suspicion is that fread() is
 complaining that &data[len] isn't valid (i.e. the buffer isn't large
 enough to hold the requested number of items), rather than simply trying
 to read them and seeing if it hits EOF before it segfaults.

 I suggest changing runFormation() to only try to read as many items as it
 has space for, i.e. replace the existing code with the commented-out
 version in:

 {{{
   //for (size_t i=0; i< nb_runs; i++) {
   while(!instream->eof()) {
     //crt_run_size = (i == nb_runs-1) ? last_run_size: run_size;

     //SDEBUG cout << "i=" << i << ":  runsize=" << crt_run_size << ", ";

     crt_run_size = makeRun_Block(instream, data, run_size, cmp);
 /* #ifdef BLOCKED_RUN */
 /*     makeRun(instream, data, crt_run_size, cmp); */
 /* #else         */
 /*     makeRun_Block(instream, data, crt_run_size, cmp); */
 /* #endif */
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/grass/ticket/775#comment:6>
GRASS GIS <http://grass.osgeo.org>


More information about the grass-dev mailing list