From b9bcf33a8d83a3cae72d7896ce0da6e378f4632a Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 5 Sep 2012 08:42:21 +0000 Subject: [PATCH] OSX compatibility fix git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35532 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSScanner.m | 28 ++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd4955000..fbd3ac2cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2012-09-05 Richard Frith-Macdonald + + * Source/NSScanner.m: Compatibility tweak reported by hns@computer.org + A string like '1.2eX' where X is not a numeric exponent, needs to be + scanned as a float/double up to (but not including) the 'e' (or 'E') + rather than being treated as a badly formatted float/double. + 2012-09-04 Fred Kiefer * Tests/base/NSXMLDocument/cdata.m: New test case for CDATA. diff --git a/Source/NSScanner.m b/Source/NSScanner.m index 3593a3b11..22875a524 100644 --- a/Source/NSScanner.m +++ b/Source/NSScanner.m @@ -724,32 +724,28 @@ typedef GSString *ivars; /* Check for trailing exponent */ if ((_scanLocation < myLength()) && ((c == 'e') || (c == 'E'))) { + unsigned int expScanLocation = _scanLocation; int expval; + _scanLocation++; if ([self _scanInt: &expval]) { - /* Check for exponent overflow */ - if (num) - { - if ((exponent > 0) && (expval > (LONG_MAX - exponent))) - exponent = LONG_MAX; - else if ((exponent < 0) && (expval < (LONG_MIN - exponent))) - exponent = LONG_MIN; - else - exponent += expval; - } + /* Check for exponent overflow */ + if (num) + { + if ((exponent > 0) && (expval > (LONG_MAX - exponent))) + exponent = LONG_MAX; + else if ((exponent < 0) && (expval < (LONG_MIN - exponent))) + exponent = LONG_MIN; + else + exponent += expval; + } } else { -#ifdef _ACCEPT_BAD_EXPONENTS_ /* Numbers like 1.23eFOO are accepted (as 1.23). */ _scanLocation = expScanLocation; -#else - /* Numbers like 1.23eFOO are rejected. */ - _scanLocation = saveScanLocation; - return NO; -#endif } } if (value)