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

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

[Octave-bug-tracker] [bug #35852] fscanf does not read full file


From: John W. Eaton
Subject: [Octave-bug-tracker] [bug #35852] fscanf does not read full file
Date: Thu, 21 Jun 2012 18:37:14 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.5) Gecko/20100101 Firefox/10.0.5 Iceweasel/10.0.5

Follow-up Comment #30, bug #35852 (project octave):

How about the attached patch?

With the change, we avoid multiple calls to putback between reads and use
tellg/seekg ot reset the stream position, but only if there is a failure.  So
there should be no problem when reading valid files with Inf, NaN, NA or just
plain numbers.  The only problem I see is that the stream positioning might
not work correctly when reading streams that don't format match expectations. 
Repositioning should work properly when reading from actual files opened in
binary mode.  Probably not when reading from pipes, and maybe not if using
text mode files (I can't remember what happens there) but Octave opens files
in binary mode by default on all systems.

But in any case, if you need robust parsing, you probably shouldn't be relying
on handling errors with scanf anyway -- look at where the read pointer ends up
for things like '2e+x' with the '%f' format (same behavior in C, so this is
not a problem unique to Octave).

But at least this change should fix the original problem, which was apparently
random failures when reading valid input files.

If you agree that this change looks OK, I'll apply it to the stable branch and
the fix will appear in 3.6.3.

(file #26079)
    _______________________________________________________

Additional Item Attachment:

File name: diffs.txt                      Size:6 KB


    _______________________________________________________

Reply to this item at:

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

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




reply via email to

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