diff options
author | André Goddard Rosa <andre.goddard@gmail.com> | 2009-12-14 21:00:56 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-12-15 11:53:29 -0500 |
commit | 6c356634111c5a7a48264d7c9ec28559e4be11a2 (patch) | |
tree | 580b71e1e3764c4cc92ae9df5275b161c61f3267 /lib | |
parent | 0f4f81dce93774a447da3ceb98cce193ef84a3fa (diff) |
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')
-rw-r--r-- | lib/vsprintf.c | 9 |
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 { \ | |||
1496 | case FORMAT_TYPE_STR: { | 1496 | case FORMAT_TYPE_STR: { |
1497 | const char *save_str = va_arg(args, char *); | 1497 | const char *save_str = va_arg(args, char *); |
1498 | size_t len; | 1498 | size_t len; |
1499 | |||
1499 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE | 1500 | if ((unsigned long)save_str > (unsigned long)-PAGE_SIZE |
1500 | || (unsigned long)save_str < PAGE_SIZE) | 1501 | || (unsigned long)save_str < PAGE_SIZE) |
1501 | save_str = "(null)"; | 1502 | save_str = "(null)"; |
1502 | len = strlen(save_str); | 1503 | len = strlen(save_str) + 1; |
1503 | if (str + len + 1 < end) | 1504 | if (str + len < end) |
1504 | memcpy(str, save_str, len + 1); | 1505 | memcpy(str, save_str, len); |
1505 | str += len + 1; | 1506 | str += len; |
1506 | break; | 1507 | break; |
1507 | } | 1508 | } |
1508 | 1509 | ||