]> git.ipfire.org Git - thirdparty/json-c.git/commitdiff
Fix bad usage of strncat introduces in 1a94c70. Pointed out by @rouault in PR #331.
authorEric Haszlakiewicz <erh+git@nimenees.com>
Sun, 9 Jul 2017 22:04:18 +0000 (15:04 -0700)
committerEric Haszlakiewicz <erh+git@nimenees.com>
Sun, 9 Jul 2017 22:04:18 +0000 (15:04 -0700)
json_object.c

index 3f6298e29294b0b9df2507c27f8f82227481a13f..2abf4df5fec4d826eaa45c2822dcbdc4a6dcc6bf 100644 (file)
@@ -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