summaryrefslogtreecommitdiffstats
path: root/contrib/gdtoa
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2007-12-16 21:13:54 +0000
committerdas <das@FreeBSD.org>2007-12-16 21:13:54 +0000
commitb2367c2d0b77fb617f31b9fafae0c52dc8ecf89e (patch)
tree99a413b129902674c3731c5f84599f3f6b72e2db /contrib/gdtoa
parentb3d67d43ffdbca81d3bce98a57c9f3e24ee9e743 (diff)
downloadFreeBSD-src-b2367c2d0b77fb617f31b9fafae0c52dc8ecf89e.zip
FreeBSD-src-b2367c2d0b77fb617f31b9fafae0c52dc8ecf89e.tar.gz
Some changes the vendor didn't want:
- Accept the '0x' prefix so strtod("nan(0x...)", NULL) returns the same thing as gcc's builtin nan("0x...") for such strings. - Don't return uninitialized memory. - Finish processing the string up to the closing ')' (provided it's lexically valid) for compatibility with C99 and *scanf().
Diffstat (limited to 'contrib/gdtoa')
-rw-r--r--contrib/gdtoa/hexnan.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/contrib/gdtoa/hexnan.c b/contrib/gdtoa/hexnan.c
index 591cad1..6faea78 100644
--- a/contrib/gdtoa/hexnan.c
+++ b/contrib/gdtoa/hexnan.c
@@ -29,6 +29,8 @@ THIS SOFTWARE.
/* Please send bug reports to David M. Gay (dmg at acm dot org,
* with " at " changed at "@" and " dot " changed to "."). */
+/* $FreeBSD$ */
+
#include "gdtoaimp.h"
static void
@@ -71,8 +73,14 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
x1 = xe = x;
havedig = hd0 = i = 0;
s = *sp;
+
+ /* FreeBSD local: Accept (but ignore) the '0x' prefix. */
+ if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X'))
+ s += 2;
+
while(c = *(CONST unsigned char*)++s) {
if (!(h = hexdig[c])) {
+#if 0
if (c <= ' ') {
if (hd0 < havedig) {
if (x < x1 && i < 8)
@@ -92,7 +100,8 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
*sp = s + 1;
break;
}
- return STRTOG_NaN;
+#endif
+ break;
}
havedig++;
if (++i > 8) {
@@ -103,9 +112,7 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
}
*x = (*x << 4) | h & 0xf;
}
- if (!havedig)
- return STRTOG_NaN;
- if (x < x1 && i < 8)
+ if (havedig && x < x1 && i < 8)
L_shift(x, x1, i);
if (x > x0) {
x1 = x0;
@@ -119,6 +126,7 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
if ( (i = nbits & (ULbits-1)) !=0)
*xe &= ((ULong)0xffffffff) >> (ULbits - i);
}
+ if (havedig) {
for(x1 = xe;; --x1) {
if (*x1 != 0)
break;
@@ -127,5 +135,22 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
break;
}
}
+ }
+
+ /*
+ * FreeBSD local: Accept all the sequences allowed by C99 and update
+ * the tail pointer correctly. Don't accept any invalid sequences.
+ */
+ if (c == '\0') /* nan() calls this, too; tolerate a missing ')' */
+ return STRTOG_NaNbits;
+ if (c != ')') {
+ while(c = *(CONST unsigned char*)++s) {
+ if (c == ')')
+ break;
+ if (!isalnum(c) && c != '_')
+ return STRTOG_NaNbits;
+ }
+ }
+ *sp = s + 1;
return STRTOG_NaNbits;
}
OpenPOWER on IntegriCloud