--- -/lib/vsprintf.c +++ +/lib/vsprintf.c @@ -3287,17 +3287,25 @@ str = skip_spaces(str); } + if (!*fmt) + break; + /* anything that is not a conversion must match exactly */ - if (*fmt != '%' && *fmt) { + if (*fmt != '%') { if (*fmt++ != *str++) break; continue; } - if (!*fmt) - break; + /* %% must match % */ + if (*fmt == '%') { + if (*fmt++ != *str++) + break; + continue; + } + /* skip this conversion. * advance both strings to next white space */ @@ -3315,6 +3323,13 @@ continue; } + if (*fmt == 'n') { + /* return number of characters read so far */ + *va_arg(args, int *) = str - buf; + ++fmt; + continue; + } + /* get field width */ field_width = -1; if (isdigit(*fmt)) { @@ -3325,30 +3340,18 @@ /* get conversion qualifier */ qualifier = -1; - if (*fmt == 'h' || _tolower(*fmt) == 'l' || - *fmt == 'z') { + if (*fmt == 'z' || *fmt == 'L') qualifier = *fmt++; + else if (*fmt == 'h' || *fmt == 'l') { if (unlikely(qualifier == *fmt)) { - if (qualifier == 'h') { - qualifier = 'H'; - fmt++; - } else if (qualifier == 'l') { - qualifier = 'L'; - fmt++; - } + qualifier = _toupper(qualifier); + fmt++; } } if (!*fmt) break; - if (*fmt == 'n') { - /* return number of characters read so far */ - *va_arg(args, int *) = str - buf; - ++fmt; - continue; - } - if (!*str) break; @@ -3450,11 +3453,6 @@ fallthrough; case 'u': break; - case '%': - /* looking for '%' in str */ - if (*str++ != '%') - return num; - continue; default: /* invalid format; stop here */ return num;