Skip to content

Commit 9d69451

Browse files
committed
clarify return value
1 parent d94caac commit 9d69451

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/lib_json/json_writer.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,45 +67,44 @@ std::string valueToString(double value) {
6767
// Allocate a buffer that is more than large enough to store the 16 digits of
6868
// precision requested below.
6969
char buffer[32];
70+
int len = -1;
7071

7172
// Print into the buffer. We need not request the alternative representation
7273
// that always has a decimal point because JSON doesn't distingish the
7374
// concepts of reals and integers.
7475
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with
7576
// visual studio 2005 to
7677
// avoid warning.
77-
int len;
7878
#if defined(WINCE)
7979
len = _snprintf(buffer, sizeof(buffer), "%.16g", value);
8080
#else
8181
len = sprintf_s(buffer, sizeof(buffer), "%.16g", value);
8282
#endif
83-
assert(len>=0);
84-
fixNumericLocale(buffer, buffer + len);
8583
#else
8684
if ( isfinite( value ))
8785
{
88-
int len = snprintf(buffer, sizeof(buffer), "%.16g", value);
89-
assert(len>=0);
90-
fixNumericLocale(buffer, buffer + len);
86+
len = snprintf(buffer, sizeof(buffer), "%.16g", value);
9187
}
9288
else
9389
{
9490
// IEEE standard states that NaN values will not compare to themselves
9591
if ( value != value)
9692
{
97-
snprintf(buffer, sizeof(buffer), "null");
93+
len = snprintf(buffer, sizeof(buffer), "null");
9894
}
9995
else if ( value < 0)
10096
{
101-
snprintf(buffer, sizeof(buffer), "-1e+9999");
97+
len = snprintf(buffer, sizeof(buffer), "-1e+9999");
10298
}
10399
else
104100
{
105-
snprintf(buffer, sizeof(buffer), "1e+9999");
101+
len = snprintf(buffer, sizeof(buffer), "1e+9999");
106102
}
103+
// For those, we do not need to call fixNumLoc, but it is fast.
107104
}
108105
#endif
106+
assert(len>=0);
107+
fixNumericLocale(buffer, buffer + len);
109108
return buffer;
110109
}
111110

0 commit comments

Comments
 (0)