lkml.org 
[lkml]   [2015]   [Nov]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 07/14] lib/vsprintf.c: slightly refactor vscnprintf()
Date
If we're given a size of 0, the vsnprintf() won't have any side
effects, and neither "i < size" or "size != 0" will trigger. So we
might as well return 0 immediately.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
lib/vsprintf.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 8af5535fd738..e22a6189548f 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2036,13 +2036,14 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
{
int i;

+ if (unlikely(!size))
+ return 0;
+
i = vsnprintf(buf, size, fmt, args);

if (likely(i < size))
return i;
- if (size != 0)
- return size - 1;
- return 0;
+ return size - 1;
}
EXPORT_SYMBOL(vscnprintf);

--
2.6.1


\
 
 \ /
  Last update: 2015-11-23 23:01    [W:0.093 / U:0.648 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site