Skip to content

Commit 42ca02b

Browse files
authored
Fix sign mismatch in valueToString
`valueToString` takes an argument `unsigned int precision`, but it is used with `%d` rather than `%u` in the `snprintf` format string. Make the format string look for an unsigned value instead.
1 parent e6a588a commit 42ca02b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: src/lib_json/json_writer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ JSONCPP_STRING valueToString(double value, bool useSpecialFloats, unsigned int p
125125
int len = -1;
126126

127127
char formatString[15];
128-
snprintf(formatString, sizeof(formatString), "%%.%dg", precision);
128+
snprintf(formatString, sizeof(formatString), "%%.%ug", precision);
129129

130130
// Print into the buffer. We need not request the alternative representation
131131
// that always has a decimal point because JSON doesn't distinguish the

0 commit comments

Comments
 (0)