This commit is contained in:
1 parent
55ecae3e58
commit
7b7a76e161
1 file changed
+3
-4
+3
-4
@@ -774,12 +774,11 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
|
||||
if (!format)
|
||||
format = std_format;
|
||||
size = snprintf(buf, sizeof(buf), format, jso->o.c_double);
|
||||
if (modf(jso->o.c_double, &dummy) == 0)
|
||||
if (modf(jso->o.c_double, &dummy) == 0 && size >= 0 && size < (int)sizeof(buf) - 2)
|
||||
{
|
||||
// Ensure it looks like a float, even if snprintf didn't.
|
||||
strncat(buf, ".0", sizeof(buf) - 1);
|
||||
if (size >= 0)
|
||||
size += 2; // yes, even if strncat ran out of room
|
||||
strcat(buf, ".0");
|
||||
size += 2;
|
||||
}
|
||||
}
|
||||
// although unlikely, snprintf can fail
|
||||
|
||||
Reference in new issue
Block a user