From mboxrd@z Thu Jan 1 00:00:00 1970 From: Darwin Rambo Date: Thu, 19 Dec 2013 15:14:19 -0800 Subject: [U-Boot] [PATCH] lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabled Message-ID: <1387494859-25158-1-git-send-email-drambo@broadcom.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de When CONFIG_SYS_VSNPRINTF is enabled, it protects print operations such as sprintf, snprintf, vsnprintf, etc., from buffer overflows. But vsnprintf_internal includes the terminating NULL character in the calculation of number of characters written. This affects sprintf and snprintf return values. Fix this issue by setting pointer 'str' back to the location of the '\0'. Signed-off-by: Darwin Rambo Reviewed-by: Steve Rae --- lib/vsprintf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 82e5c13..60874da 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -750,6 +750,7 @@ repeat: ADDCH(str, '\0'); if (str > end) end[-1] = '\0'; + --str; } #else *str = '\0'; -- 1.7.9.5