From: Changli Gao Date: Tue, 26 Oct 2010 21:22:50 +0000 (-0700) Subject: lib: fix scnprintf() if @size is == 0 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b903c0b8899b46829a9b80ba55b61079b35940ec;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git lib: fix scnprintf() if @size is == 0 scnprintf() should return 0 if @size is == 0. Update the comment for it, as @size is unsigned. Signed-off-by: Changli Gao Cc: Ingo Molnar Cc: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 8378c136b6e1..c150d3dafff4 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -1504,7 +1504,7 @@ EXPORT_SYMBOL(snprintf); * @...: Arguments for the format string * * The return value is the number of characters written into @buf not including - * the trailing '\0'. If @size is <= 0 the function returns 0. + * the trailing '\0'. If @size is == 0 the function returns 0. */ int scnprintf(char *buf, size_t size, const char *fmt, ...) @@ -1516,7 +1516,11 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...) i = vsnprintf(buf, size, fmt, args); va_end(args); - return (i >= size) ? (size - 1) : i; + if (likely(i < size)) + return i; + if (size != 0) + return size - 1; + return 0; } EXPORT_SYMBOL(scnprintf);