fix (and test) for bug #43722

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38213 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2014-11-29 11:02:23 +00:00
parent e6ed085192
commit ca81536515
3 changed files with 29 additions and 9 deletions

View file

@ -1,3 +1,8 @@
2014-11-29 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSScanner.m: Fixup error in scanning doubles with excess
precision (bug #43722).
2014-11-28 johannes@brilliantservice.co.jp
* Source/NSThread.m: Set thread name visible to OS
@ -19,7 +24,7 @@
2014-11-20 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRunLoop.m: Avoinf some unnecessary retain/release cycles.
* Source/NSRunLoop.m: Avoind some unnecessary retain/release cycles.
2014-11-05 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -1243,6 +1243,7 @@ GSScanDouble(unichar *buf, unsigned length, double *result)
int exponent = 0;
BOOL negativeMantissa = NO;
BOOL negativeExponent = NO;
BOOL extra = NO;
unsigned pos = 0;
int mantissaLength;
int dotPos = -1;
@ -1301,14 +1302,8 @@ GSScanDouble(unichar *buf, unsigned length, double *result)
{
/* Mantissa too long ... ignore excess.
*/
if (19 == mantissaLength && (dotPos < 0 || dotPos >= mantissaLength))
{
mantissaLength--;
}
else
{
mantissaLength = 19;
}
mantissaLength = 18;
extra = YES;
}
if (dotPos < 0)
{

View file

@ -28,6 +28,26 @@ int main()
d = [@" 1.2" doubleValue];
PASS(d > 1.199999 && d < 1.200001, "doubleValue with leading space works");
s = @"50.6468746467461646";
sscanf([s UTF8String], "%lg", &d);
PASS(EQ([s doubleValue], d), "50.6468746467461646 -doubleValue OK");
s = @"50.64687464674616461";
sscanf([s UTF8String], "%lg", &d);
PASS(EQ([s doubleValue], d), "50.64687464674616461 -doubleValue OK");
s = @"0.646874646746164616898211";
sscanf([s UTF8String], "%lg", &d);
PASS(EQ([s doubleValue], d), "0.646874646746164616898211 -doubleValue OK");
s = @"502.646874646746164";
sscanf([s UTF8String], "%lg", &d);
PASS(EQ([s doubleValue], d), "502.646874646746164 -doubleValue OK");
s = @"502.6468746467461646";
sscanf([s UTF8String], "%lg", &d);
PASS(EQ([s doubleValue], d), "502.6468746467461646 -doubleValue OK");
s = [NSString stringWithCharacters: &u length: 1];
PASS_EQUAL(s, @"£", "UTF-8 string literal matches 16bit unicode string");