Skip to contentSkip to conversation

(Minor) Bugfixes to vsprintf.c, vsscanf().

PATCH In review johan verrept 1 participant 2 messages Oct 18, 2001

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 (Minor) Bugfixes to vsprintf.c, vsscanf().

hello,

minor bugfix for vsprintf.c, vsscanf did not discard whitespace in input:
- when encoutering whitespace in fmt not followed by '%'
- in conversion where result is ignored with '*'

There is another bugfix in this, don't know from who. (picked it up with uml) (vsscanf used to skip two characters in the fmt for a single char in the input if not in conversion.)

Patch against 2.4.12, I am afraid.

enjoy,

	J.
#1 lore raw
Quoted 7 lines · johan verrept

hello,

minor bugfix for vsprintf.c, vsscanf did not discard whitespace in input:
- when encoutering whitespace in fmt not followed by '%'
- in conversion where result is ignored with '*'

Quoted 5 lines

There is another bugfix in this, don't know from who. (picked it up with uml) (vsscanf used to skip two characters in the fmt for a single char in the input if not in conversion.)

Patch against 2.4.12, I am afraid.

Attached patch is beter. Both bugs are fixed and it adds fieldwidth support for conversions with ignored results.
Again against 2.4.12.

	J.
lib/vsprintf.c +21 -3
@@ -525,12 +525,15 @@
 	for (; *fmt; fmt++) {
 		/* skip any white space in format */
 		if (isspace(*fmt)) {
+			/* space in fmt skips all space in input */
+			while (isspace(*str)) str++;
 			continue;
 		}
 
 		/* anything that is not a conversion must match exactly */
 		if (*fmt != '%') {
-			if (*fmt++ != *str++)
+			/* Don't bump fmt because the for header will do it */
+			if (*fmt != *str++)
 				return num;
 			continue;
 		}
@@ -540,10 +543,25 @@
 		 * advance both strings to next white space
 		 */
 		if (*fmt == '*') {
-			while (!isspace(*fmt))
+			fmt++;
+			/* get fieldwidth */
+			field_width = 0xffffffffUL;
+			if (isdigit(*fmt))
+				field_width = skip_atoi(&fmt);
+
+			/* skip possible conversion qualifier */
+			if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt == 'Z')
 				fmt++;
-			while(!isspace(*str))
+
+			/* do not skip conversion char, the for loop will do this */
+
+			/* eat all whitespace before conversion! */
+			while(isspace(*str))
+				str++;
+			while(!isspace(*str) && field_width) {
+				field_width--;
 				str++;
+			}
 			continue;
 		}