Re: [PATCH] Fix %x parsing in vsscanf()

From: Deepak Saxena
Date: Tue Sep 23 2003 - 19:53:42 EST


On Sep 23 2003, at 23:26, viro@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx was caught saying:
> The following, AFAICS, would be correct:
>
> if (*cp == '0') {
> cp++;
> if (unlikely((*cp == 'x' || *cp == 'X') && isxdigit(cp[1]))) {
> if (!base || base == 16) {
> cp++;
> base = 16;
> }
> } else if (!base)
> base = 8;
> } else if (!base)
> base = 10;

We can remove everything but "base = 10;" from the second "else if"
clause b/c by this point we're guaranteed that it's not a hex or
octal value.

===== lib/vsprintf.c 1.16 vs edited =====
--- 1.16/lib/vsprintf.c Sat Jul 12 12:49:57 2003
+++ edited/lib/vsprintf.c Tue Sep 23 17:56:50 2003
@@ -32,16 +32,17 @@
{
unsigned long result = 0,value;

- if (!base) {
+ if (*cp == '0') {
+ cp++;
+ if (unlikely((*cp == 'x' || *cp == 'X') && isxdigit(cp[1]))) {
+ if (!base || base == 16) {
+ cp++;
+ base = 16;
+ }
+ } else if (!base)
+ base = 8;
+ } else if (!base) {
base = 10;
- if (*cp == '0') {
- base = 8;
- cp++;
- if ((*cp == 'x') && isxdigit(cp[1])) {
- cp++;
- base = 16;
- }
- }
}
while (isxdigit(*cp) &&
(value = isdigit(*cp) ? *cp-'0' : toupper(*cp)-'A'+10) < base) {
@@ -76,16 +77,17 @@
{
unsigned long long result = 0,value;

- if (!base) {
+ if (*cp == '0') {
+ cp++;
+ if (unlikely((*cp == 'x' || *cp == 'X') && isxdigit(cp[1]))) {
+ if (!base || base == 16) {
+ cp++;
+ base = 16;
+ }
+ } else if (!base)
+ base = 8;
+ } else if (!base) {
base = 10;
- if (*cp == '0') {
- base = 8;
- cp++;
- if ((*cp == 'x') && isxdigit(cp[1])) {
- cp++;
- base = 16;
- }
- }
}
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp)
? toupper(*cp) : *cp)-'A'+10) < base) {



--
Deepak Saxena
MontaVista Software - Powering the Embedded Revolution - www.mvista.com
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/