Browse Source

Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault in PR #331.

tags/json-c-0.13-20171207
Eric Haszlakiewicz 8 years ago
parent
commit
7b7a76e161
1 changed files with 3 additions and 4 deletions
  1. +3
    -4
      json_object.c

+ 3
- 4
json_object.c View File

@@ -774,12 +774,11 @@ static int json_object_double_to_json_string_format(struct json_object* jso,
if (!format) if (!format)
format = std_format; format = std_format;
size = snprintf(buf, sizeof(buf), format, jso->o.c_double); 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. // 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 // although unlikely, snprintf can fail


Loading…
Cancel
Save