From 7c2575d72352405c858ecec1618c60cdd98dd1d6 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 21 Jul 2005 23:03:26 +0000 Subject: [PATCH] Josh discovered a bug parsing negative numbers with leading zeros ("-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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/simgear/nasal/string.c b/simgear/nasal/string.c index a94468c6..8a96ba97 100644 --- a/simgear/nasal/string.c +++ b/simgear/nasal/string.c @@ -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; } -- 2.39.5