This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
libstdc++/8716: std::string( NULL, 0 ) throws exception also on zero length
- From: x at sources dot redhat dot com, at at sources dot redhat dot com, zsch dot de at sources dot redhat dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 26 Nov 2002 13:51:32 -0000
- Subject: libstdc++/8716: std::string( NULL, 0 ) throws exception also on zero length
- Reply-to: x at sources dot redhat dot com, at at sources dot redhat dot com, zsch dot de at sources dot redhat dot com
>Number: 8716
>Category: libstdc++
>Synopsis: std::string( NULL, 0 ) throws exception also on zero length
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Nov 26 05:56:02 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Joacim Zschimmer
>Release: gcc 3.2
>Organization:
>Environment:
Linux
>Description:
The constructor string::string(const char*,int) throws an exception if the length is zero and the pointer is null. The string-constructor should accept string(s,0), even if const char* s = NULL.
The constructor should check the pointer only if there are some bytes the pointer points to. With zero length there are no bytes and a NULL-pointer should be allowed. Throwing an exception on NULL is quite good (better then SEGV), but only if the pointer is really to be used.
Sincerly
Joacim Zschimmer
>How-To-Repeat:
#include <string>
using namespace std;
int main( int, char** )
{
try
{
const char* s = NULL;
string a = string( s, 0 );
printf( "ok\n" );
return 0;
}
catch( const exception& x ) { printf( "%s\n", x.what() ); return 1; }
}
>Fix:
Only check the (const char*)-Pointer, when length is not zero.
This is in libstdc++-v3/include/bits/basic_string.tcc line 143.
>Release-Note:
>Audit-Trail:
>Unformatted: