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: Roman Hiestand
Subject: [Octave-bug-tracker] [bug #35852] fscanf does not read full file
Date: Tue, 05 Jun 2012 11:06:35 +0000
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0

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

I think I have found the problem. With the generous help of Michael Goffioul I
was able to build a debug version of Octave 3.6.2 on Windows (MSVC).
The problem is that ungetc/putback on a stream can fail in certain conditions,
which is the case here. The condition in which ungetc/putback can fail is
when previously there were two successive calls to std::istream::get(), when
for the second one the buffer was empty and got refilled. The first
putback/ungetc
then works, while the second fails. It is questionable anyway to call
putback/ungetc twice in a row, I found several comments on the web that this
might fail also with glibc.

In the header of ungetc this is documented (Copyright Microsoft):
*Exit:
*       returns ch
*       returns EOF if tried to push EOF, stream not opened for reading or
*       or if we have already ungetc'd back to beginning of buffer.

See also
http://msdn.microsoft.com/en-us/library/29hykw2y%28VS.90%29.aspx
http://www.gnu.org/software/libc/manual/html_node/How-Unread.html#How-Unread

In our case, ungetc then returns EOF, the eof-bit is set in the stream and
fscanf is aborted. This is the call stack where the error occurs:

>       msvcr90.dll!_ungetc_nolock(int ch=45, _iobuf * str=0x729f7408)  Line 73 
> C
        msvcr90.dll!ungetc(int ch=45, _iobuf * stream=0x729f7408)  Line 53 + 0xb
bytes   C
        vc90-liboctinterp-1.dll!c_file_ptr_buf::pbackfail(int c=45)  Line 96 + 
0x25
bytes   C++
        msvcp90.dll!std::basic_streambuf<char,std::char_traits<char>
>::sputbackc(char _Ch='-')  Line 143    C++
        msvcp90.dll!std::basic_istream<char,std::char_traits<char> 
>::putback(char
_Ch='-')  Line 771 + 0x15 bytes C++
        vc90-liboctave-1.dll!0073f6e5()         
        [Frames below may be incorrect and/or missing, no symbols loaded for
vc90-liboctave-1.dll]   
        
vc90-liboctinterp-1.dll!octave_scan<double>(std::basic_istream<char,std::char_traits<char>
> & is={...}, const scanf_format_elt & fmt={...}, double * valptr=0x0018ecb4) 
Line 1233 + 0xa bytes   C++
        vc90-liboctinterp-1.dll!do_scanf_conv<double
*>(std::basic_istream<char,std::char_traits<char> > & is={...}, const
scanf_format_elt & fmt={...}, double * valptr=0x0018ecb4, Matrix & mval={...},
double * data=0x08721d48, int & idx=18767, int & conversion_count=18767, int
nr=7, int max_size=28672, bool discard=false)  Line 1253 + 0x11 bytes   C++
        vc90-liboctinterp-1.dll!octave_base_stream::do_scanf(scanf_format_list &
fmt_list={...}, int nr=7, int nc=-1, bool one_elt_size_spec=false, int &
conversion_count=18767, const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
who="fscanf")  Line 1769 + 0x31 bytes   C++
        vc90-liboctinterp-1.dll!octave_base_stream::scanf(const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
fmt="%f", const Array<double> & size={...}, int & conversion_count=18767,
const std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
who="fscanf")  Line 1943 + 0x2b bytes   C++
        vc90-liboctinterp-1.dll!octave_stream::scanf(const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
fmt="%f", const Array<double> & size={...}, int & count=18767, const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
who="fscanf")  Line 3689 + 0x1e bytes   C++
        vc90-liboctinterp-1.dll!octave_stream::scanf(const octave_value & 
fmt={...},
const Array<double> & size={...}, int & count=18767, const
std::basic_string<char,std::char_traits<char>,std::allocator<char> > &
who="fscanf")  Line 3707 + 0x22 bytes   C++
        vc90-liboctinterp-1.dll!Ffscanf(const octave_value_list & args={...}, 
int
__formal=1)  Line 1161 + 0x24 bytes     C++

For some reason the debugger had problems with liboctave, but there it is in
the function template <> double octave_read_value (std::istream& is), line 284
in lo-utils.cc.

As a fix I propose the following: Remove the second putback, negate the
double. In the '+' case, leave out putback altogether.
Please tell me what you think, I'm open for feedback/suggestions/criticism.
Should you accept the patch, I'd be glad if one of the Octave developers could
merge it into the source repository.
I have run all the test cases on this page (except the %i case), all work
fine.


(file #25985)
    _______________________________________________________

Additional Item Attachment:

File name: lo-utils.cc.patch              Size:0 KB


    _______________________________________________________

Reply to this item at:

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

_______________________________________________
  Nachricht gesendet von/durch Savannah
  http://savannah.gnu.org/




reply via email to

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