[PATCH RESEND] parser: handle negative numbers properly

Robert Morell rmorell at nvidia.com
Mon Apr 1 14:54:23 PDT 2013


Numbers beginning with '-' were falling into the DASH category.

This also caused a confusing error message, since no terminating NUL
character was added to configRBuf -- old garbage in the string would be
printed.  This fixes the terminating NUL for COMMA as well.

Signed-off-by: Robert Morell <rmorell at nvidia.com>
---

Without this change, the server fails with an unintelligible message such as:
" -reen0" is not a valid keyword in this section.

 hw/xfree86/parser/scan.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/hw/xfree86/parser/scan.c b/hw/xfree86/parser/scan.c
index f852b83..b74d21b 100644
--- a/hw/xfree86/parser/scan.c
+++ b/hw/xfree86/parser/scan.c
@@ -338,18 +338,26 @@ xf86getToken(xf86ConfigSymTabRec * tab)
 
         /* GJA -- handle '-' and ','  * Be careful: "-hsync" is a keyword. */
         else if ((c == ',') && !isalpha(configBuf[configPos])) {
+            configRBuf[i] = '\0';
             return COMMA;
         }
-        else if ((c == '-') && !isalpha(configBuf[configPos])) {
+        else if ((c == '-') && !isalnum(configBuf[configPos])) {
+            configRBuf[i] = '\0';
             return DASH;
         }
 
         /* 
          * Numbers are returned immediately ...
          */
-        if (isdigit(c)) {
+        if (isdigit(c) || (c == '-' && isdigit(configBuf[configPos]))) {
             int base;
 
+            i = 0;
+            if (c == '-') {
+                configRBuf[i++] = c;
+                c = configBuf[configPos++];
+            }
+
             if (c == '0')
                 if ((configBuf[configPos] == 'x') ||
                     (configBuf[configPos] == 'X')) {
@@ -365,8 +373,7 @@ xf86getToken(xf86ConfigSymTabRec * tab)
                 val.numType = PARSE_DECIMAL;
             }
 
-            configRBuf[0] = c;
-            i = 1;
+            configRBuf[i++] = c;
             while (isdigit(c = configBuf[configPos++]) ||
                    (c == '.') || (c == 'x') || (c == 'X') ||
                    ((base == 16) && (((c >= 'a') && (c <= 'f')) ||
@@ -374,7 +381,7 @@ xf86getToken(xf86ConfigSymTabRec * tab)
                 configRBuf[i++] = c;
             configPos--;        /* GJA -- one too far */
             configRBuf[i] = '\0';
-            val.num = strtoul(configRBuf, NULL, 0);
+            val.num = strtol(configRBuf, NULL, 0);
             val.realnum = atof(configRBuf);
             return NUMBER;
         }
-- 
1.8.1.5



More information about the xorg-devel mailing list