aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAnton Arapov <aarapov@redhat.com>2011-01-12 19:59:49 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2011-01-13 11:03:10 -0500
commitb921c69fb262988ff7856493a8453661a1bac814 (patch)
tree87496b306fb609adcbf65b2fe5151a49e0957ca6 /lib
parenta3f938bf6f5746d39e013d03ba13118a393fee96 (diff)
lib/vsprintf.c: fix vscnprintf() if @size is == 0
vscnprintf() should return 0 if @size is == 0. Update the comment for it, as @size is unsigned. This change based on the code of commit b903c0b8899b46829a9b80ba55b61079b35940ec ("lib: fix scnprintf() if @size is == 0") moves the real fix into vscnprinf() from scnprintf() and makes scnprintf() call vscnprintf(), thus avoid code duplication. Signed-off-by: Anton Arapov <aarapov@redhat.com> Acked-by: Changli Gao <xiaosuo@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/vsprintf.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 6ff38524ec16..d3023df8477f 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1473,7 +1473,7 @@ EXPORT_SYMBOL(vsnprintf);
1473 * @args: Arguments for the format string 1473 * @args: Arguments for the format string
1474 * 1474 *
1475 * The return value is the number of characters which have been written into 1475 * The return value is the number of characters which have been written into
1476 * the @buf not including the trailing '\0'. If @size is <= 0 the function 1476 * the @buf not including the trailing '\0'. If @size is == 0 the function
1477 * returns 0. 1477 * returns 0.
1478 * 1478 *
1479 * Call this function if you are already dealing with a va_list. 1479 * Call this function if you are already dealing with a va_list.
@@ -1487,7 +1487,11 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
1487 1487
1488 i = vsnprintf(buf, size, fmt, args); 1488 i = vsnprintf(buf, size, fmt, args);
1489 1489
1490 return (i >= size) ? (size - 1) : i; 1490 if (likely(i < size))
1491 return i;
1492 if (size != 0)
1493 return size - 1;
1494 return 0;
1491} 1495}
1492EXPORT_SYMBOL(vscnprintf); 1496EXPORT_SYMBOL(vscnprintf);
1493 1497
@@ -1535,14 +1539,10 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)
1535 int i; 1539 int i;
1536 1540
1537 va_start(args, fmt); 1541 va_start(args, fmt);
1538 i = vsnprintf(buf, size, fmt, args); 1542 i = vscnprintf(buf, size, fmt, args);
1539 va_end(args); 1543 va_end(args);
1540 1544
1541 if (likely(i < size)) 1545 return i;
1542 return i;
1543 if (size != 0)
1544 return size - 1;
1545 return 0;
1546} 1546}
1547EXPORT_SYMBOL(scnprintf); 1547EXPORT_SYMBOL(scnprintf);
1548 1548