summaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorAndré Goddard Rosa <andre.goddard@gmail.com>2009-12-15 03:00:56 +0100
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-15 17:53:29 +0100
commit6c356634111c5a7a48264d7c9ec28559e4be11a2 (patch)
tree580b71e1e3764c4cc92ae9df5275b161c61f3267 /lib/vsprintf.c
parentvsprintf: factorize "(null)" string (diff)
downloadlinux-6c356634111c5a7a48264d7c9ec28559e4be11a2.tar.xz
linux-6c356634111c5a7a48264d7c9ec28559e4be11a2.zip
vsprintf: pre-calculate final string length for later use
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com> Acked-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index e5ab51fc2d9e..99747a58ec72 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1496,13 +1496,14 @@ do { \
case FORMAT_TYPE_STR: {
const char *save_str = va_arg(args, char *);
size_t len;
+
if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE
|| (unsigned long)save_str < PAGE_SIZE)
save_str = "(null)";
- len = strlen(save_str);
- if (str + len + 1 < end)
- memcpy(str, save_str, len + 1);
- str += len + 1;
+ len = strlen(save_str) + 1;
+ if (str + len < end)
+ memcpy(str, save_str, len);
+ str += len;
break;
}