Skip to content

Commit

Permalink
lib: fix scnprintf() if @SiZe is == 0
Browse files Browse the repository at this point in the history
scnprintf() should return 0 if @SiZe is == 0. Update the comment for it,
as @SiZe is unsigned.

Signed-off-by: Changli Gao <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xiaosuo authored and torvalds committed Oct 26, 2010
1 parent 5e05798 commit b903c0b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand All @@ -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);

Expand Down

0 comments on commit b903c0b

Please sign in to comment.