snprintf already calculated the length

This commit is contained in:
Matthias Loy 2014-08-14 20:58:02 +02:00 committed by Christopher Dunn
parent fe2cd01e80
commit 64d591b720

View File

@ -74,15 +74,18 @@ std::string valueToString(double value) {
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with
// visual studio 2005 to
// avoid warning.
size_t len;
#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
fixNumericLocale(buffer, buffer + len);
#else
if ( isfinite( value ))
{
snprintf(buffer, sizeof(buffer), "%.16g", value);
{
size_t len = snprintf(buffer, sizeof(buffer), "%.16g", value);
fixNumericLocale(buffer, buffer + len);
}
else
{
@ -99,12 +102,8 @@ std::string valueToString(double value) {
{
snprintf(buffer, sizeof(buffer), "1e+9999");
}
// nothing more to do, return.
return buffer;
}
#endif
fixNumericLocale(buffer, buffer + strlen(buffer));
return buffer;
}