From 7b7a76e161a2b727e68ce26c32c2fb3467682840 Mon Sep 17 00:00:00 2001 From: Eric Haszlakiewicz Date: Sun, 9 Jul 2017 15:04:18 -0700 Subject: [PATCH] Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault in PR #331. --- json_object.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/json_object.c b/json_object.c index 3f6298e292..2abf4df5fe 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