[syslinux:elflink] stdio: Fix unhexchar() for hex digits > 9

syslinux-bot for Matt Fleming matt.fleming at intel.com
Mon Dec 3 06:21:09 PST 2012


Commit-ID:  0163d235652d2cc8f0564da7470983ee450a8a91
Gitweb:     http://www.syslinux.org/commit/0163d235652d2cc8f0564da7470983ee450a8a91
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Mon, 3 Dec 2012 13:27:11 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Mon, 3 Dec 2012 13:28:11 +0000

stdio: Fix unhexchar() for hex digits > 9

There was a typographical error in commit 9f51b69d7c050 ("core:
Reimplement lots asm code in C") which re-wrote the asm implementation
of unhexchar() in C. We should be adding 10, not subtracting to get
the equivalent decimal integer. Also be explicit about the sign of
'data' and 'num'.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/include/stdio.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/com32/include/stdio.h b/com32/include/stdio.h
index 902a0e8..813a0ed 100644
--- a/com32/include/stdio.h
+++ b/com32/include/stdio.h
@@ -124,9 +124,9 @@ __extern int rename(const char *, const char *);
  *
  * Returns 0 if 'data' was converted succesfully, -1 otherwise.
  */
-static inline int unhexchar(char *data)
+static inline int unhexchar(unsigned char *data)
 {
-	char num = *data;
+	unsigned char num = *data;
 
 	if (num >= '0' && num <= '9') {
 		*data = num - '0';
@@ -134,7 +134,7 @@ static inline int unhexchar(char *data)
 	} else {
 		num |= 0x20;	/* upper case -> lower case */
 		if (num >= 'a' && num <= 'f') {
-			*data = num - 'a' - 10;
+			*data = num - 'a' + 10;
 			return 0;
 		}
 	}


More information about the Syslinux-commits mailing list