mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-26 18:51:04 +08:00
Merge pull request #30 from mloy/redundant-strlen
This commit is contained in:
commit
033677cc1a
@ -105,8 +105,7 @@ static inline char *duplicateStringValue(const char *value,
|
||||
/** Free the string duplicated by duplicateStringValue().
|
||||
*/
|
||||
static inline void releaseStringValue(char *value) {
|
||||
if (value)
|
||||
free(value);
|
||||
free(value);
|
||||
}
|
||||
|
||||
} // namespace Json
|
||||
|
@ -67,6 +67,7 @@ std::string valueToString(double value) {
|
||||
// Allocate a buffer that is more than large enough to store the 16 digits of
|
||||
// precision requested below.
|
||||
char buffer[32];
|
||||
int len = -1;
|
||||
|
||||
// Print into the buffer. We need not request the alternative representation
|
||||
// that always has a decimal point because JSON doesn't distingish the
|
||||
@ -75,36 +76,35 @@ std::string valueToString(double value) {
|
||||
// visual studio 2005 to
|
||||
// avoid warning.
|
||||
#if defined(WINCE)
|
||||
_snprintf(buffer, sizeof(buffer), "%.16g", value);
|
||||
len = _snprintf(buffer, sizeof(buffer), "%.16g", value);
|
||||
#else
|
||||
sprintf_s(buffer, sizeof(buffer), "%.16g", value);
|
||||
len = sprintf_s(buffer, sizeof(buffer), "%.16g", value);
|
||||
#endif
|
||||
#else
|
||||
if ( isfinite( value ))
|
||||
{
|
||||
snprintf(buffer, sizeof(buffer), "%.16g", value);
|
||||
len = snprintf(buffer, sizeof(buffer), "%.16g", value);
|
||||
}
|
||||
else
|
||||
{
|
||||
// IEEE standard states that NaN values will not compare to themselves
|
||||
if ( value != value)
|
||||
{
|
||||
snprintf(buffer, sizeof(buffer), "null");
|
||||
len = snprintf(buffer, sizeof(buffer), "null");
|
||||
}
|
||||
else if ( value < 0)
|
||||
{
|
||||
snprintf(buffer, sizeof(buffer), "-1e+9999");
|
||||
len = snprintf(buffer, sizeof(buffer), "-1e+9999");
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf(buffer, sizeof(buffer), "1e+9999");
|
||||
len = snprintf(buffer, sizeof(buffer), "1e+9999");
|
||||
}
|
||||
// nothing more to do, return.
|
||||
return buffer;
|
||||
// For those, we do not need to call fixNumLoc, but it is fast.
|
||||
}
|
||||
|
||||
#endif
|
||||
fixNumericLocale(buffer, buffer + strlen(buffer));
|
||||
assert(len>=0);
|
||||
fixNumericLocale(buffer, buffer + len);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user