[PATCH] lib: fix scnprintf() if @size is == 0

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Changli Gao
Date: Tuesday, August 24, 2010 - 4:35 pm

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>
---
 lib/vsprintf.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 7af9d84..0c66ae9 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,7 @@ 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;
+	return (i >= size) ? (size != 0 ? (size - 1) : 0) : i;
 }
 EXPORT_SYMBOL(scnprintf);
 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] lib: fix scnprintf() if @size is == 0, Changli Gao, (Tue Aug 24, 4:35 pm)
Re: [PATCH] lib: fix scnprintf() if @size is == 0, Joe Perches, (Tue Aug 24, 5:03 pm)
Re: [PATCH] lib: fix scnprintf() if @size is == 0, Changli Gao, (Tue Aug 24, 5:10 pm)
Re: [PATCH] lib: fix scnprintf() if @size is == 0, Joe Perches, (Tue Aug 24, 5:35 pm)
Re: [PATCH] lib: fix scnprintf() if @size is == 0, Changli Gao, (Tue Aug 24, 5:44 pm)