This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11818] New: istrstream::operator>> generates wrong output and corrupts source string


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11818

           Summary: istrstream::operator>> generates wrong output and
                    corrupts source string
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: llewins at raytheon dot com
                CC: gcc-bugs at gcc dot gnu dot org,llewins at raytheon dot
                    com
 GCC build triplet: i686-pc-cygwin
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin

istrstream::operator>> fails to read an unsigned number correctly from a source 
string. In addition, it corrupts the source string. Consider the following code:

#include <iostream>
#include <strstream>
#include <string>

using namespace std;

int main(void)
{
    string line(".p 13");
    const char* const c = line.substr(3).c_str();
    cout
         << unsigned(c[0])
         << unsigned(c[1])
         << unsigned(c[2])
         << endl;
    cout << c << endl;
    istrstream is(c);
    cout << c << endl;
    unsigned outSize;
    is >> outSize;
    cout << c << endl;
    cout << outSize << endl;
}

When compiled with gcc2.95, it gives the expected results:

49510
13
13
13
13

When compiled with gcc3.2, it gives incorrect results AND the underlying string 
c appears to be corrupted:

49510
13
13
1                     <- string c corrupted
1                     <- should have output 13

This version of gcc came with cygwin, and was configured as follows:

Reading specs from /usr/lib/gcc-lib/i686-pc-cygwin/3.2/specs
Configured with: /netrel/src/gcc-3.2-3/configure --enable-languages=c,c++,f77,ja
va --enable-libgcj --enable-threads=posix --with-system-zlib --enable-nls --with
out-included-gettext --enable-interpreter --disable-sjlj-exceptions --disable-ve
rsion-specific-runtime-libs --enable-shared --build=i686-pc-linux --host=i686-pc
-cygwin --target=i686-pc-cygwin --enable-haifa --prefix=/usr --exec-prefix=/usr
--sysconfdir=/etc --libdir=/usr/lib --includedir=/nonexistent/include --libexecd
ir=/usr/sbin
Thread model: posix
gcc version 3.2 20020927 (prerelease)


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