jsoncpp icon indicating copy to clipboard operation
jsoncpp copied to clipboard

Value constructor for char * is crashing on NULL value in current version jsoncpp 0.6.0

Open abhianshu opened this issue 12 years ago • 2 comments

In earlier version of Json::value constructor i.e. Value( const char *value ) was handling NULL as parameter gracefully But crashing In version jsoncpp 0.6.0.

Why this change is done, any specific issue related to that?

abhianshu avatar Nov 26 '14 08:11 abhianshu

The NULL literal isn't a const char_, so this would be very dangerous: Value(NULL). You don't know what constructor you're calling. Value(static_cast<const char_>(NULL)) would be more clear, but even then I think the code has a logical problem. A C++ std::string can be constructed with a (const char*)0 in the sense that it compiles, but it's undefined behavior. That string constructor requires that the argument point to an array of char, and passing 0 is a violation of that precondition.

BillyGoto avatar Nov 26 '14 15:11 BillyGoto

Agreed.

cdunn2001 avatar Dec 01 '14 01:12 cdunn2001