[OctDev] Re: (octave-forge) segfault in dlmread

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[OctDev] Re: (octave-forge) segfault in dlmread

David Bateman-3
Tom Bergan wrote:

>Hello, I believe there's a bug in dlmread - it segfaults when the file is empty.
> This fix works on my machine:
>
>line 159:
>  if((long int)flen == 0) {
>      // file is empty
>    ComplexMatrix cm(0,0);
>    retval(0) = cm;
>    return retval;
>  }
>  OCTAVE_LOCAL_BUFFER(char,line,(long int)flen)
>
>I'm not familiar enough with the code to know if this fix is suitable, so I
>haven't added this to CVS.
>
>-Tom Bergan
>
>  
>
I think I'd be inclined to do the patch something like the attached...
However, its not my code and so I'll let someone else comment before
applying it..

D.

--
David Bateman                                [hidden email]
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 1 69 35 77 01 (Fax)
91193 Gif-Sur-Yvette FRANCE

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary


*** dlmread.cc~ 2005-05-30 11:17:11.000000000 +0200
--- dlmread.cc 2005-10-03 11:44:05.175763158 +0200
***************
*** 164,173 ****
--- 164,175 ----
      //skip first r0 - 1 lines
    for (unsigned long i=0;i<r0;i++) {
      file.getline(line,flen,'\n');
+     if (file.eof()) goto empty_file;
    }
   
      // get first line
    file.getline(line,flen,'\n');
+   if (file.eof()) goto empty_file;
    do {
      istringstream lstrm(line);
      lineq = read_textline(&lstrm,sep);
***************
*** 208,213 ****
--- 210,216 ----
      }
      retval(0) = cm;
    }
+  empty_file:
   
    return retval;
  }