octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #44662] [OF io] csv2cell.cc miscompiled with O


From: Dan Sebald
Subject: [Octave-bug-tracker] [bug #44662] [OF io] csv2cell.cc miscompiled with Octave built for 64-bit windows
Date: Sun, 29 Mar 2015 19:06:57 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 SeaMonkey/2.15

Follow-up Comment #1, bug #44662 (project octave):

Here is the documentation on the streams getline function:

http://www.cplusplus.com/reference/istream/istream/getline/

Hard to debug without it failing here, but just a couple suggestions to look
at from your perspective.

The fact that the exact location of failure changes based upon what lines you
add or remove suggests to me the bug (probably a memory violation) occurs
sooner in the file.

One thing that stands out is that in this code:


/* Buffers */
192 char line [MAXSTRINGLENGTH];
193 std::string str, word;
194 bool inside = false;
195
196 /* Read headerlines */
197 for (long ii=0; ii < hlines; ii++)
198 {
199 fd.getline (line, MAXSTRINGLENGTH);
200 if (fd.tellg () >= fdend || fd.fail ())
201 return octave_value (Cell (0, 0));
202 }


the character buffer length is MAXSTRINGLENGTH, rather than MAXSTRINGLENGTH+1.
 The documentation suggests that a ' ' is added to the end.  So if the file in
question is, say by mistake, a binary file or happens to have a line greater
than MAXSTRINGLENGTH will fd.getline() write past the end of the line[]
buffer?  Try making the code:


char line [MAXSTRINGLENGTH+1];


and see if that helps.

Another question is whether the last line of this code:


260 fd.getline (line, MAXSTRINGLENGTH);
261 while (fd.fail ())
262 {
263 fd.clear ();
264 str += line;
265 fd.getline (line, MAXSTRINGLENGTH);
266 }
267 str += line; 


does anything.  Probably a nicer way of programming these loops is more along
the lines:


while (fd.fail ())
{
    fd.getline (line, MAXSTRINGLENGTH);
    if (fd.gcount () > 0)
        str += line;
}


using the function described in the documentation.  Then there isn't any code
need before and after the loop.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?44662>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]