Bug in 2.1.30 and 2.1.31 -- fscanf in "C" compatibility mode

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bug in 2.1.30 and 2.1.31 -- fscanf in "C" compatibility mode

Joao Cardoso-3

Hi,

The following ilustrate the bug on a two line file:

---po----
One: 1
Two: 2
---------

octave:1> f=fopen("po","r");
octave:2> a=fscanf(f,"One: %d\n")
a = 1
octave:3> ftell(f)
ans = 7
octave:4> a=fscanf(f,"Two: %d\n")
a = 2
octave:5> frewind(f)
ans = 0
octave:6> a=fscanf(f,"One: %d\n","C")
a = 1
octave:7> ftell(f)
ans = -1
octave:8> frewind(f)
ans = 0
octave:9> a=fscanf(f,"One: %d","C")
a = 1
octave:10> ftell(f)
ans = -1

And thus the second file line can't be read.

If the file is read line by line with 'fgetl' and than 'sscanf',
everything is OK.

Joao


Reply | Threaded
Open this post in threaded view
|

Bug in 2.1.30 and 2.1.31 -- fscanf in "C" compatibility mode

John W. Eaton-6
On 20-Jul-2000, Joao Cardoso <[hidden email]> wrote:

| The following ilustrate the bug on a two line file:
|
| ---po----
| One: 1
| Two: 2
| ---------
|
| octave:1> f=fopen("po","r");
| octave:2> a=fscanf(f,"One: %d\n")
| a = 1
| octave:3> ftell(f)
| ans = 7
| octave:4> a=fscanf(f,"Two: %d\n")
| a = 2
| octave:5> frewind(f)
| ans = 0
| octave:6> a=fscanf(f,"One: %d\n","C")
| a = 1
| octave:7> ftell(f)
| ans = -1
| octave:8> frewind(f)
| ans = 0
| octave:9> a=fscanf(f,"One: %d","C")
| a = 1
| octave:10> ftell(f)
| ans = -1
|
| And thus the second file line can't be read.
|
| If the file is read line by line with 'fgetl' and than 'sscanf',
| everything is OK.

I think the following patch should fix this problem.  I've checked it
in to the CVS archive.

Thanks,

jwe


2000-07-20  John W. Eaton  <[hidden email]>

        * oct-stream.cc (octave_base_stream::oscanf): Advance to next
        format element before attempting to pick up any trailing stuff.


Index: oct-stream.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/oct-stream.cc,v
retrieving revision 1.65
diff -u -r1.65 oct-stream.cc
--- oct-stream.cc 2000/03/31 23:33:26 1.65
+++ oct-stream.cc 2000/07/20 19:18:12
@@ -1897,6 +1897,9 @@
       if (ok () && len > nconv)
  {
   octave_value tmp;
+
+  elt = fmt_list.next ();
+
   do_oscanf (elt, tmp);
  }
     }