summaryrefslogtreecommitdiffstats
path: root/contrib/gdtoa/hexnan.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2011-03-12 07:03:06 +0000
committerdas <das@FreeBSD.org>2011-03-12 07:03:06 +0000
commit22b42559b254072c025ee7660742d9096d6ddbfd (patch)
tree02fea95a802135fbb5d2f67a8c005bf132b6e256 /contrib/gdtoa/hexnan.c
parentbb4fe3b8f6c28c422e237503dec22ccea5269dba (diff)
parenta0113107f8ebf649eb6c0730ece07fe0865a384b (diff)
downloadFreeBSD-src-22b42559b254072c025ee7660742d9096d6ddbfd.zip
FreeBSD-src-22b42559b254072c025ee7660742d9096d6ddbfd.tar.gz
Merge gdtoa-20110304.
Diffstat (limited to 'contrib/gdtoa/hexnan.c')
-rw-r--r--contrib/gdtoa/hexnan.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/contrib/gdtoa/hexnan.c b/contrib/gdtoa/hexnan.c
index 58952db..a443721 100644
--- a/contrib/gdtoa/hexnan.c
+++ b/contrib/gdtoa/hexnan.c
@@ -29,10 +29,6 @@ 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 <ctype.h>
-
#include "gdtoaimp.h"
static void
@@ -75,14 +71,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'))
+ /* allow optional initial 0x or 0X */
+ while((c = *(CONST unsigned char*)(s+1)) && c <= ' ')
+ ++s;
+ if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
+ && *(CONST unsigned char*)(s+3) > ' ')
s += 2;
-
- while(c = *(CONST unsigned char*)++s) {
+ while((c = *(CONST unsigned char*)++s)) {
if (!(h = hexdig[c])) {
-#if 0
if (c <= ' ') {
if (hd0 < havedig) {
if (x < x1 && i < 8)
@@ -96,14 +92,26 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
x1 = x;
i = 0;
}
+ while(*(CONST unsigned char*)(s+1) <= ' ')
+ ++s;
+ if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')
+ && *(CONST unsigned char*)(s+3) > ' ')
+ s += 2;
continue;
}
if (/*(*/ c == ')' && havedig) {
*sp = s + 1;
break;
}
+#ifndef GDTOA_NON_PEDANTIC_NANCHECK
+ do {
+ if (/*(*/ c == ')') {
+ *sp = s + 1;
+ break;
+ }
+ } while((c = *++s));
#endif
- break;
+ return STRTOG_NaN;
}
havedig++;
if (++i > 8) {
@@ -112,9 +120,11 @@ hexnan( CONST char **sp, FPI *fpi, ULong *x0)
i = 1;
*--x = 0;
}
- *x = (*x << 4) | h & 0xf;
+ *x = (*x << 4) | (h & 0xf);
}
- if (havedig && x < x1 && i < 8)
+ if (!havedig)
+ return STRTOG_NaN;
+ if (x < x1 && i < 8)
L_shift(x, x1, i);
if (x > x0) {
x1 = x0;
@@ -128,7 +138,6 @@ 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;
@@ -137,22 +146,5 @@ 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