From c8a82362f5ace2a2e2754d05839e397ba1928513 Mon Sep 17 00:00:00 2001 From: rfm Date: Wed, 29 Oct 2008 09:16:17 +0000 Subject: [PATCH] allow longer double values. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26991 72102866-910b-0410-8b05-ffd578937521 --- Source/GSString.m | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/Source/GSString.m b/Source/GSString.m index 0f057bf23..d6ddf9819 100644 --- a/Source/GSString.m +++ b/Source/GSString.m @@ -1499,13 +1499,27 @@ doubleValue_c(GSStr self) } else { - unsigned l = (end - ptr) < 32 ? (end - ptr) : 31; - unichar buf[l+1]; - unichar *b = buf; + unsigned s = 99; + unichar b[100]; + unichar *u = b; double d = 0.0; - GSToUnicode(&b, &l, (const uint8_t*)ptr, l, internalEncoding, 0, 0); - GSScanDouble(b, l, &d); + /* use static buffer unless string is really long, in which case + * we use the stack to allocate a bigger one. + */ + if (GSToUnicode(&u, &s, (const uint8_t*)ptr, end - ptr, + internalEncoding, NSDefaultMallocZone(), GSUniTerminate) == NO) + { + return 0.0; + } + if (GSScanDouble(u, end - ptr, &d) == NO) + { + d = 0.0; + } + if (u != b) + { + NSZoneFree(NSDefaultMallocZone(), u); + } return d; } }