diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 637016f..14cf618 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -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 diff --git a/src/lib_json/json_writer.cpp b/src/lib_json/json_writer.cpp index 76a3fb5..e52fe4a 100644 --- a/src/lib_json/json_writer.cpp +++ b/src/lib_json/json_writer.cpp @@ -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; }