This is the mail archive of the
libstdc++-prs@sourceware.cygnus.com
mailing list for the libstdc++ project.
libstdc++/3: Segmentation Faults in substr() and string()
- To: libstdc++-gnats@sourceware.cygnus.com
- Subject: libstdc++/3: Segmentation Faults in substr() and string()
- From: bmosher@csc.com
- Date: 25 Aug 1999 18:39:51 -0000
- Reply-To: bmosher@csc.com
- Resent-Cc: libstdc++-prs@sourceware.cygnus.com,
- Resent-Reply-To: gnats-admin@sourceware.cygnus.com, bmosher@csc.com
- Resent-To: nobody@sourceware.cygnus.com
>Number: 3
>Category: libstdc++
>Synopsis: Segmentation Faults in substr() and string()
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Aug 25 11:47:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator: Bob Mosher, Computer Sciences Corporation (210)733-4825
>Release: 2.8.1, 2.8.1.1
>Organization:
>Environment:
SPARC Ultra 60, Solaris 2.6, gcc 2.8.1
>Description:
Example One ( segfault in substr() ):
This segfault happens after correctly handling five other
substr() calls in three separate source code modules.
I've tried:
- string s = current_line(21,4);
- string s = current_line(21);
- string s(current_line,21,4);
- string s(current_line,21);
- removing and reinstalling the compiler and associated libraries;
- replacing the RAM;
Nothing helps.
Source code snippet:
ulong
rta:: ParseConnectionNumber(string current_line )
{
string s = current_line;
unsigned long connection_number = 0;
string cnumber = s.substr(21); // segfault here
return connection_number;
}
Error message reported by gdb:
Program received signal SIGSEGV, Segmentation fault.
0x1bbe8 in basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >::replace (this=0xefffefc8,
pos=0, n1=0, s=0xa6d25 " 157", n2=4) at stl/stl_alloc.h:407
stl/stl_alloc.h:407: No such file or directory.
stl_alloc.h is present and I had "-I/usr/local/include/g++"
in the makefile.
Example Two ( segfault in string() ):
If I comment out the offending line in Example One, Example Two appears
in a different code module. The while() loop correctly processes
eleven lines of text before segfaulting on the twelfth, which is a
blank line. Of the eleven lines correctly processed, two were blank.
You'll note the error messages are nearly identical.
Source code snippet:
Parse44():
int i = 24;
while(!found)
{
fin.getline( buffer, LINELENGTH, '\n' );
cout << "Parse44() buffer[" << i << "] = " << buffer << endl;
str = string(buffer); // segfault here
cout << "Parse44() str = " << str << endl;
}
Error message reported by gdb:
Program received signal SIGSEGV, Segmentation fault.
0x1bb58 in basic_string<char, string_char_traits<char>, __default_alloc_template<false, 0> >::replace (this=0xeffff050,
pos=0, n1=0, s=0xeffff170 "", n2=0) at stl/stl_alloc.h:407
stl/stl_alloc.h:407: No such file or directory.
>How-To-Repeat:
I wish I could keep it from repeating.
>Fix:
Not a clue.
>Release-Note:
>Audit-Trail:
>Unformatted: