* [PATCH v2] lib: fix scnprintf() if @size is == 0
@ 2010-08-25 1:41 Changli Gao
0 siblings, 0 replies; only message in thread
From: Changli Gao @ 2010-08-25 1:41 UTC (permalink / raw)
To: akpm; +Cc: Joe Perches, linux-kernel, Changli Gao
scnprintf() should return 0 if @size is == 0. Update the comment for it,
as @size is unsigned.
Signed-off-by: Changli Gao <xiaosuo@gmail.com>
---
v2: use if to improve readability and add likely()
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7af9d84..f9c327a 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1497,7 +1497,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, ...)
@@ -1509,7 +1509,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);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2010-08-25 1:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-25 1:41 [PATCH v2] lib: fix scnprintf() if @size is == 0 Changli Gao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®