r11084: - allow hex numbers with 'a'...'f' digits to be parsed
authorStefan Metzmacher <metze@samba.org>
Sat, 15 Oct 2005 09:28:56 +0000 (09:28 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:44:45 +0000 (13:44 -0500)
- parse hex numbers correct

tridge: how could we submit this to the upstream appweb library?

metze
(This used to be commit 70cde83c134f2d8bb2f6c0649b7f87a8846e63a4)

source4/lib/appweb/ejs/ejsLex.c
source4/lib/appweb/mpr/var.c

index b4617a638e7ed68853b0a142e74d56a200fb57ba..b9a363cfc9c2d957f385038d77a26f63c246bc86 100644 (file)
@@ -633,12 +633,19 @@ static int getLexicalToken(Ejs *ep, int state)
                                break;
                        }
                        if (tolower(c) == 'x') {
-                               if (tokenAddChar(ep, c) < 0) {
-                                       return EJS_TOK_ERR;
-                               }
-                               if ((c = inputGetc(ep)) < 0) {
-                                       break;
-                               }
+                               do {
+                                       if (tokenAddChar(ep, c) < 0) {
+                                               return EJS_TOK_ERR;
+                                       }
+                                       if ((c = inputGetc(ep)) < 0) {
+                                               break;
+                                       }
+                               } while (isdigit(c) || (tolower(c) >= 'a' && tolower(c) <= 'f'));
+
+                               mprDestroyVar(&ep->tokenNumber);
+                               ep->tokenNumber = mprParseVar(ep->token, type);
+                               inputPutback(ep, c);
+                               return EJS_TOK_NUMBER;
                        }
                        if (! isdigit(c)) {
 #if BLD_FEATURE_FLOATING_POINT
index 09979156e89103972ab5b14d21664160a38d4a87..011d668460d371f542993d5759d5ba076508b236 100644 (file)
@@ -2015,7 +2015,7 @@ int64 mprParseInteger64(char *str)
                                if (isdigit(c)) {
                                        num64 = (c - '0') + (num64 * radix);
                                } else if (c >= 'a' && c <= 'f') {
-                                       num64 = (c - 'a') + (num64 * radix);
+                                       num64 = (c - ('a' - 10)) + (num64 * radix);
                                } else {
                                        break;
                                }
@@ -2132,7 +2132,7 @@ int mprParseInteger(char *str)
                                if (isdigit(c)) {
                                        num = (c - '0') + (num * radix);
                                } else if (c >= 'a' && c <= 'f') {
-                                       num = (c - 'a') + (num * radix);
+                                       num = (c - ('a' - 10)) + (num * radix);
                                } else {
                                        break;
                                }