public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers
@ 2002-01-19 14:10 paolo
  0 siblings, 0 replies; 3+ messages in thread
From: paolo @ 2002-01-19 14:10 UTC (permalink / raw)
  To: doerntge, gcc-bugs, gcc-prs, nobody

Synopsis: std::ifstream::operator>>(int&) fails with negative hex numbers

State-Changed-From-To: analyzed->closed
State-Changed-By: paolo
State-Changed-When: Sat Jan 19 14:10:28 2002
State-Changed-Why:
    In fact, the behaviour of libstdc++-v3 is strictly standard
    conforming. Indeed, according to 22.2.2.2.2, Table 57, the
    stdio equivalent of the conversion is %x, thus leading to
    ffffffd6 for -42 (i.e., equivalent to printf("%x", -42)).
    When the read is attempted it does *not* fit in a signed
    int i, and it fails. You can fix your code by using an
    unsigned int i.
    
    Cheers,
    Paolo.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5424


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers
@ 2002-01-18 13:51 paolo
  0 siblings, 0 replies; 3+ messages in thread
From: paolo @ 2002-01-18 13:51 UTC (permalink / raw)
  To: doerntge, gcc-bugs, gcc-prs, nobody

Synopsis: std::ifstream::operator>>(int&) fails with negative hex numbers

State-Changed-From-To: feedback->analyzed
State-Changed-By: paolo
State-Changed-When: Fri Jan 18 13:51:00 2002
State-Changed-Why:
    The testcase:
    
    #include <fstream>
    #include <iostream>
    
    bool stream_in( void )
    {
      std::ifstream is( "foo.txt" );
      is.setf( std::ios::hex, std::ios::basefield );
    
      int i=0;
      if ( !(is.good() && is.is_open()) )
        return false;
      is >> i;
      if ( !is )
        return false;
      if ( is.peek() == '\n' )
        is.ignore();
      if ( !is )
        return false;
      is >> i;
      if ( !is )
        return false;
      if ( is.peek() == '\n' )
        is.ignore();
      if ( !is )
        return false;
      return true;
    }
    
    bool stream_out( void )
    {
      std::ofstream os( "foo.txt" );
      os.setf( std::ios::hex, std::ios::basefield );
      if ( !(os.good() && os.is_open()) )
        return false;
    
      os << -42 << '\n' << 42 << '\n';
    
      return true;
    }
    
    int main( int argc, char*argv[] )
    {
      if ( !stream_out() )
        std::cerr << "std::ostream failed" << std::endl;
      else if ( !stream_in() )
        std::cerr << "std::istream failed" << std::endl;
      return 0;
    }

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5424


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers
@ 2002-01-18  5:04 paolo
  0 siblings, 0 replies; 3+ messages in thread
From: paolo @ 2002-01-18  5:04 UTC (permalink / raw)
  To: doerntge, gcc-bugs, gcc-prs, nobody

Synopsis: std::ifstream::operator>>(int&) fails with negative hex numbers

State-Changed-From-To: open->feedback
State-Changed-By: paolo
State-Changed-When: Fri Jan 18 05:04:16 2002
State-Changed-Why:
    In order to ease the processing of your PR, could you
    please provide a self-contained testcase?
    
    
    Thanks,
    Paolo.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5424


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-01-19 22:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-19 14:10 libstdc++/5424: std::ifstream::operator>>(int&) fails with negative hex numbers paolo
  -- strict thread matches above, loose matches on Subject: below --
2002-01-18 13:51 paolo
2002-01-18  5:04 paolo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).