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]

Re: libstdc++/7961: compare( char *) implemented incorrectly.


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


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