mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Deepak Saxena <dsaxena@mvista.com>
To: viro@parcelfarce.linux.theplanet.co.uk
Cc: Deepak Saxena <dsaxena@mvista.com>,
	Linus Torvalds <torvalds@osdl.org>,
	linux-kernel@vger.kernel.org, marcelo.tosatti@cyclades.com.br
Subject: Re: [PATCH] Fix %x parsing in vsscanf()
Date: Tue, 23 Sep 2003 18:02:58 -0700	[thread overview]
Message-ID: <20030924010258.GA24014@xanadu.az.mvista.com> (raw)
In-Reply-To: <20030923222632.GO7665@parcelfarce.linux.theplanet.co.uk>

On Sep 23 2003, at 23:26, viro@parcelfarce.linux.theplanet.co.uk 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

  reply	other threads:[~2003-09-24  0:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-09-23 21:22 Deepak Saxena
2003-09-23 21:26 ` viro
2003-09-23 21:28 ` Linus Torvalds
2003-09-23 21:35   ` viro
2003-09-23 22:16     ` Deepak Saxena
2003-09-23 22:26       ` viro
2003-09-24  1:02         ` Deepak Saxena [this message]
2003-09-24  0:55           ` viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030924010258.GA24014@xanadu.az.mvista.com \
    --to=dsaxena@mvista.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.tosatti@cyclades.com.br \
    --cc=torvalds@osdl.org \
    --cc=viro@parcelfarce.linux.theplanet.co.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®