]> git.mxchange.org Git - simgear.git/commitdiff
Josh discovered a bug parsing negative numbers with leading zeros
authorandy <andy>
Thu, 21 Jul 2005 23:03:26 +0000 (23:03 +0000)
committerandy <andy>
Thu, 21 Jul 2005 23:03:26 +0000 (23:03 +0000)
("-0.3") which also affected ones of the form "-.3".  This got
introduced a few months back, I'm not sure how it went undetected for
so long...

simgear/nasal/string.c

index a94468c67d57321b8bb5cba6a6e44d8224ea987e..8a96ba970643005188749a6097a74de689cc7e5a 100644 (file)
@@ -175,6 +175,13 @@ static int tonum(unsigned char* s, int len, double* result)
     if(len == 1 && s[0] == '.')
         return 0;
 
+    // Strip off the leading negative sign first, so we can correctly
+    // parse things like -.xxx which would otherwise confuse
+    // readsigned.
+    if(len > 1 && s[0] == '-' && s[1] != '-') {
+        sgn = -1; s++; len--;
+    }
+
     // Read the integer part
     i = readsigned(s, len, i, &val);
     if(val < 0) { sgn = -1; val = -val; }