From 3c7f2de01b7abdb8ca28a41d4ee5124a333cff63 Mon Sep 17 00:00:00 2001 From: dmiller Date: Sun, 29 Dec 2019 05:53:27 +0000 Subject: [PATCH] Properly return negative on error from vsnprintf Our implementation of vsnprintf for systems where it is missing did not correctly return a negative value on error, instead returning the size passed in. We got this code from tcpdump/libpcap, and it was wrong there, too, though their latest master branch has removed it in favor of requiring a C99 compiler (C99 guarantees vsnprintf). This should remove a LGTM code analysis finding (See #1834) of cpp/constant-comparison in Ncat because we were checking for a negative return from Snprintf, which would never occur. --- nbase/snprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nbase/snprintf.c b/nbase/snprintf.c index 102f1ff1a..0680786e5 100644 --- a/nbase/snprintf.c +++ b/nbase/snprintf.c @@ -639,7 +639,7 @@ vsnprintf (char *str, size_t sz, const char *format, va_list args) ret = xyzprintf (&state, format, args); *state.s = '\0'; if (ret) - return sz; + return -1; else return state.s - state.str; }