Skip to content

Commit

Permalink
vsprintf: pre-calculate final string length for later use
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
André Goddard Rosa authored and Linus Torvalds committed Dec 15, 2009
1 parent 0f4f81d commit 6c35663
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/vsprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 6c35663

Please sign in to comment.