]> granicus.if.org Git - json-c/commitdiff
sprintbuf(): test for all vsnprintf error values
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 27 Feb 2022 20:45:28 +0000 (21:45 +0100)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 6 Mar 2022 15:05:32 +0000 (16:05 +0100)
The POSIX specification states that vsnprintf returns "a negative value"
in case of error, but the code checks explicitly only for -1.

printbuf.c

index 00822fac4f19ebe6f9a5aaafea51ebf38070086b..fd4a5d9414ad2eef219b253431016477065595b9 100644 (file)
@@ -143,7 +143,7 @@ int sprintbuf(struct printbuf *p, const char *msg, ...)
         * if output is truncated whereas some return the number of bytes that
         * would have been written - this code handles both cases.
         */
-       if (size == -1 || size > 127)
+       if (size < 0 || size > 127)
        {
                va_start(ap, msg);
                if ((size = vasprintf(&t, msg, ap)) < 0)