Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.4.13-pre2 /lib/vsprintf.c

Filename:/lib/vsprintf.c
Lines Added:30
Lines Deleted:11
Also changed in: (Previous) 2.4.13-pre1  2.4.12-ac1  2.4.10-ac12  2.4.10-ac11  2.4.10-ac10  2.4.10-ac9 
(Following) 2.4.13-pre3  2.4.13-pre4  2.4.13-pre5  2.4.13-pre6  2.4.13  2.4.19-pre8 

Location
[  2.4.13-pre2
  [  lib
     o  vsprintf.c

Patch

diff -u --recursive --new-file v2.4.12/linux/lib/vsprintf.c linux/lib/vsprintf.c
--- v2.4.12/linux/lib/vsprintf.c   Sun Sep 23 11:41:01 2001
+++ linux/lib/vsprintf.c   Thu Oct 11 11:17:22 2001
@@ -18,6 +18,7 @@
 #include <linux/types.h>
 #include <linux/string.h>
 #include <linux/ctype.h>
+#include <linux/kernel.h>
 
 #include <asm/div64.h>
 
@@ -519,36 +520,44 @@
    int num = 0;
    int qualifier;
    int base;
-   unsigned int field_width;
+   int field_width = -1;
    int is_sign = 0;
 
-   for (; *fmt; fmt++) {
+   while(*fmt && *str) {
       /* skip any white space in format */
+      /* white space in format matchs any amount of
+       * white space, including none, in the input.
+       */
       if (isspace(*fmt)) {
-         continue;
+         while (isspace(*fmt))
+            ++fmt;
+         while (isspace(*str))
+            ++str;
       }
 
       /* anything that is not a conversion must match exactly */
-      if (*fmt != '%') {
+      if (*fmt != '%' && *fmt) {
          if (*fmt++ != *str++)
-            return num;
+            break;
          continue;
       }
+
+      if (!*fmt)
+         break;
       ++fmt;
       
       /* skip this conversion.
        * advance both strings to next white space
        */
       if (*fmt == '*') {
-         while (!isspace(*fmt))
+         while (!isspace(*fmt) && *fmt)
             fmt++;
-         while(!isspace(*str))
+         while (!isspace(*str) && *str)
             str++;
          continue;
       }
 
       /* get field width */
-      field_width = 0xffffffffUL;
       if (isdigit(*fmt))
          field_width = skip_atoi(&fmt);
 
@@ -561,25 +570,32 @@
       base = 10;
       is_sign = 0;
 
-      switch(*fmt) {
+      if (!*fmt || !*str)
+         break;
+
+      switch(*fmt++) {
       case 'c':
       {
          char *s = (char *) va_arg(args,char*);
+         if (field_width == -1)
+            field_width = 1;
          do {
             *s++ = *str++;
-         } while(field_width-- > 0);
+         } while(field_width-- > 0 && *str);
          num++;
       }
       continue;
       case 's':
       {
          char *s = (char *) va_arg(args, char *);
+         if(field_width == -1)
+            field_width = INT_MAX;
          /* first, skip leading white space in buffer */
          while (isspace(*str))
             str++;
 
          /* now copy until next white space */
-         while (!isspace(*str) && field_width--) {
+         while (*str && !isspace(*str) && field_width--) {
             *s++ = *str++;
          }
          *s = '\0';
@@ -620,6 +636,9 @@
        */
       while (isspace(*str))
          str++;
+
+      if (!*str || !isdigit(*str))
+         break;
 
       switch(qualifier) {
       case 'h':


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.