Hello Robert, Thursday, May 23, 2002, 11:47:26 AM, you wrote:
>> Well, this will fix the problem, but String::substr() will >> still cause a crash if for some reason a NULL pointer is >> passed to it! Btw have you read my mail till the end ? RC> Yes. The String++ implementation currently uses the <string> std class RC> to implement substr. From a quick inspection the fault is in the RC> string() constructor not returning an empty string when NULL is passed RC> to it. No! The string constructor which uses const char * as its argument - there is no check if the pointer being passed is NULL and later strlen () is called on the pointer to determined the size of the C string being passed... Here is the exact flow: 1. The constructor basic_string (const charT* s) : dat (nilRep.grab ()) { assign (s); } 2. The assign call basic_string& assign (const charT* s) { return assign (s, traits::length (s)); } 3. The call to traits::length() static size_t length (const char_type* s) { return strlen (s); } The crash happens in 3 - a string object is never constructed at all and string::substr() is never called. This is a bug of the string implementation in 2.95.3. I'am aware of this because I've done alot of usage of strings lately and was bit by this. I avoid this by calling string::assign () instead of the string (const char *) constructor which is safe. -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/