This is the mail archive of the libstdc++@sources.redhat.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patchlet] Re: <sstream> bug?


On 11 Jul 2000 at 00:02 (-0400), brent verner wrote:
| On 10 Jul 2000 at 22:01 (-0400), CH Lin wrote:
| | As a new member of this mailing list, please accept my apology if my
| | question is inappropriate or being asked somewhere else.  That said, 
| | consider the following program:
| | 
| | #include <iostream>
| | #include <sstream>
| | 
| | using namespace std;
| | 
| | int main()
| | {
| |   istringstream iss("1 2 3 4 5");
| |   int i;
| | 
| |   while (iss >> i)  cout << i << '\n';
| | }
| | 
| | using g++ 2.95.2 and libstdc++-2.90.8, the above program caused an 
| | infinite loop by repeating printing 5.  Is it a known bug? If so,
| | is there any patch available?
| 
| I'm seeing the same behavior using cvs-20000710. I'm looking at it right
| now. For whatever reason, we are not setting failbit when no int is 
| extracted from the istringstream -- looks like num_get::do_get(...) is
| the culprit, though.

_M_extract() is setting eofbit, while/after reading the last valid 
int from the stream, causing failbit, which is needed for 
void* operator(), to never have a chance of being set... what to do? 
dig into _M_extract, or hackishly set failbit when _M_extract sets 
eofbit... [don't you love it that ddd asks you to ignore a segfault!]

wait... reading through 22.2.2.1.2... I see

11  Stage 3: The result of stage 2 processing can be one of
      
      A sequence of chars has been accumulated in stage 2 that is 
      converted (according to the rules of scanf) to a value of the 
      type of val. This value is stored in val and ios_base::goodbit 
      is stored in err.

... whoohooo. so all we have to do is goodbit in the

if (sanity_checks)
  set value
  set goodbit
else
  set failbit

chunk... eofbit can be set the next time around :)

oh hell, here's a patch that should do it... for int& anyway :)

Index: locale_facets.tcc
===================================================================
RCS file: /cvs/gcc/egcs/libstdc++-v3/bits/locale_facets.tcc,v
retrieving revision 1.7
diff -c -p -3 -r1.7 locale_facets.tcc
*** locale_facets.tcc	2000/07/04 02:24:54	1.7
--- locale_facets.tcc	2000/07/12 03:53:26
*************** namespace std
*** 709,714 ****
--- 709,715 ----
            && __sanity != __xtrc && *__sanity == '\0' && errno == 0
            && __l >= INT_MIN && __l <= INT_MAX)
          __v = static_cast<int>(__l);
+         __err = ios_base::goodbit;
        else
          __err |= ios_base::failbit;
  

-- 
Damon Brent Verner                        o      _     _         _
Cracker Jack? Surprise Certified  _o     /\_   _ \\o  (_)\__/o  (_)
brent@rcfile.org                _< \_   _>(_) (_)/<_    \_| \   _|/' \/
brent@linux1.org               (_)>(_) (_)        (_)   (_)    (_)'  _\o_

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]