This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: libstdc++/7961: compare( char *) implemented incorrectly.
- From: paolo at gcc dot gnu dot org
- To: gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, john dot carter at tait dot co dot nz, nobody at gcc dot gnu dot org
- Date: 1 Nov 2002 10:23:28 -0000
- Subject: Re: libstdc++/7961: compare( char *) implemented incorrectly.
- Reply-to: paolo at gcc dot gnu dot org, gcc-bugs at gcc dot gnu dot org, gcc-prs at gcc dot gnu dot org, john dot carter at tait dot co dot nz, nobody at gcc dot gnu dot org, gcc-gnats at gcc dot gnu dot org
Synopsis: compare( char *) implemented incorrectly.
State-Changed-From-To: open->closed
State-Changed-By: paolo
State-Changed-When: Fri Nov 1 02:23:27 2002
State-Changed-Why:
Not a bug.
Indeed, no segfaults can be produced at run-time with code
like the following
// ------------
#include <string>
#include <cassert>
int main()
{
std::string lhs("abc");
lhs.append(1, '\0');
lhs += "def";
assert( lhs != "abc" );
}
// -------------
and variants thereof. From the glibc2.3.1 documentation:
- Function: int memcmp (const void *A1, const void *A2, size_t SIZE)
The function `memcmp' compares the SIZE bytes of memory beginning
at A1 against the SIZE bytes of memory beginning at A2. The value
returned has the same sign as the difference between the first
differing pair of bytes (interpreted as `unsigned char' objects,
then promoted to `int').
If the contents of the two blocks are equal, `memcmp' returns `0'.
that is, it seems to me that there is absolutely *nothing*
wrong with a '\0' embedded in the string: its just a byte
like any other.
Thanks for your report, Paolo.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7961