vsprintf: pre-calculate final string length for later use
authorAndré Goddard Rosa <andre.goddard@gmail.com>
Tue, 15 Dec 2009 02:00:56 +0000 (18:00 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 15 Dec 2009 16:53:29 +0000 (08:53 -0800)
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>
lib/vsprintf.c

index e5ab51fc2d9e4c450f1641d5ae736774dfa73b61..99747a58ec72137281c9cad363a34b52d8b14e2a 100644 (file)
@@ -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;
                }