[PATCH 03/10] parse_integer: convert sscanf()

2015-05-01 Thread Alexey Dobriyan
Remove base second guessing.

Uniformly fix too liberal acceptance in %lu/%ld cases in the next patch.

Signed-off-by: Alexey Dobriyan 
---

 lib/vsprintf.c |   36 ++--
 1 file changed, 10 insertions(+), 26 deletions(-)

--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2470,8 +2470,6 @@ EXPORT_SYMBOL_GPL(bprintf);
 int vsscanf(const char *buf, const char *fmt, va_list args)
 {
const char *str = buf;
-   char *next;
-   char digit;
int num = 0;
u8 qualifier;
unsigned int base;
@@ -2483,6 +2481,8 @@ int vsscanf(const char *buf, const char *fmt, va_list 
args)
bool is_sign;
 
while (*fmt) {
+   int len;
+
/* skip any white space in format */
/* white space in format matchs any amount of
 * white space, including none, in the input.
@@ -2611,35 +2611,22 @@ int vsscanf(const char *buf, const char *fmt, va_list 
args)
 */
str = skip_spaces(str);
 
-   digit = *str;
-   if (is_sign && digit == '-')
-   digit = *(str + 1);
-
-   if (!digit
-   || (base == 16 && !isxdigit(digit))
-   || (base == 10 && !isdigit(digit))
-   || (base == 8 && (!isdigit(digit) || digit > '7'))
-   || (base == 0 && !isdigit(digit)))
-   break;
-
if (is_sign)
-   val.s = qualifier != 'L' ?
-   simple_strtol(str, , base) :
-   simple_strtoll(str, , base);
+   len = parse_integer(str, base, );
else
-   val.u = qualifier != 'L' ?
-   simple_strtoul(str, , base) :
-   simple_strtoull(str, , base);
+   len = parse_integer(str, base, );
+   if (len < 0)
+   break;
 
-   if (field_width > 0 && next - str > field_width) {
+   if (field_width > 0) {
if (base == 0)
_parse_integer_fixup_radix(str, );
-   while (next - str > field_width) {
+   while (len > field_width) {
if (is_sign)
val.s = div_s64(val.s, base);
else
val.u = div_u64(val.u, base);
-   --next;
+   len--;
}
}
 
@@ -2680,10 +2667,7 @@ int vsscanf(const char *buf, const char *fmt, va_list 
args)
break;
}
num++;
-
-   if (!next)
-   break;
-   str = next;
+   str += len;
}
 
return num;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 03/10] parse_integer: convert sscanf()

2015-05-01 Thread Alexey Dobriyan
Remove base second guessing.

Uniformly fix too liberal acceptance in %lu/%ld cases in the next patch.

Signed-off-by: Alexey Dobriyan adobri...@gmail.com
---

 lib/vsprintf.c |   36 ++--
 1 file changed, 10 insertions(+), 26 deletions(-)

--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2470,8 +2470,6 @@ EXPORT_SYMBOL_GPL(bprintf);
 int vsscanf(const char *buf, const char *fmt, va_list args)
 {
const char *str = buf;
-   char *next;
-   char digit;
int num = 0;
u8 qualifier;
unsigned int base;
@@ -2483,6 +2481,8 @@ int vsscanf(const char *buf, const char *fmt, va_list 
args)
bool is_sign;
 
while (*fmt) {
+   int len;
+
/* skip any white space in format */
/* white space in format matchs any amount of
 * white space, including none, in the input.
@@ -2611,35 +2611,22 @@ int vsscanf(const char *buf, const char *fmt, va_list 
args)
 */
str = skip_spaces(str);
 
-   digit = *str;
-   if (is_sign  digit == '-')
-   digit = *(str + 1);
-
-   if (!digit
-   || (base == 16  !isxdigit(digit))
-   || (base == 10  !isdigit(digit))
-   || (base == 8  (!isdigit(digit) || digit  '7'))
-   || (base == 0  !isdigit(digit)))
-   break;
-
if (is_sign)
-   val.s = qualifier != 'L' ?
-   simple_strtol(str, next, base) :
-   simple_strtoll(str, next, base);
+   len = parse_integer(str, base, val.s);
else
-   val.u = qualifier != 'L' ?
-   simple_strtoul(str, next, base) :
-   simple_strtoull(str, next, base);
+   len = parse_integer(str, base, val.u);
+   if (len  0)
+   break;
 
-   if (field_width  0  next - str  field_width) {
+   if (field_width  0) {
if (base == 0)
_parse_integer_fixup_radix(str, base);
-   while (next - str  field_width) {
+   while (len  field_width) {
if (is_sign)
val.s = div_s64(val.s, base);
else
val.u = div_u64(val.u, base);
-   --next;
+   len--;
}
}
 
@@ -2680,10 +2667,7 @@ int vsscanf(const char *buf, const char *fmt, va_list 
args)
break;
}
num++;
-
-   if (!next)
-   break;
-   str = next;
+   str += len;
}
 
return num;
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/