From: Eric Haszlakiewicz Date: Sun, 9 Jul 2017 22:04:18 +0000 (-0700) Subject: Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault in PR #331. X-Git-Tag: json-c-0.13-20171207~79 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b7a76e161a2b727e68ce26c32c2fb3467682840;p=thirdparty%2Fjson-c.git Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault in PR #331. --- diff --git a/json_object.c b/json_object.c index 3f6298e2..2abf4df5 100644 --- a/json_object.c +++ b/json_object.c @@ -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