summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/arch/vax/gdtoa/strtof.c4
-rw-r--r--lib/libc/gdtoa/arithchk.c183
-rw-r--r--lib/libc/gdtoa/dmisc.c8
-rw-r--r--lib/libc/gdtoa/dtoa.c77
-rw-r--r--lib/libc/gdtoa/g_Qfmt.c119
-rw-r--r--lib/libc/gdtoa/g__fmt.c147
-rw-r--r--lib/libc/gdtoa/g_ddfmt.c169
-rw-r--r--lib/libc/gdtoa/g_dfmt.c93
-rw-r--r--lib/libc/gdtoa/g_ffmt.c93
-rw-r--r--lib/libc/gdtoa/g_xLfmt.c113
-rw-r--r--lib/libc/gdtoa/g_xfmt.c119
-rw-r--r--lib/libc/gdtoa/gdtoa.c83
-rw-r--r--lib/libc/gdtoa/gdtoa.h31
-rw-r--r--lib/libc/gdtoa/gethex.c10
-rw-r--r--lib/libc/gdtoa/hdtoa.c6
-rw-r--r--lib/libc/gdtoa/misc.c36
-rw-r--r--lib/libc/gdtoa/qnan.c110
-rw-r--r--lib/libc/gdtoa/smisc.c16
-rw-r--r--lib/libc/gdtoa/strtoIQ.c63
-rw-r--r--lib/libc/gdtoa/strtoId.c60
-rw-r--r--lib/libc/gdtoa/strtoIdd.c66
-rw-r--r--lib/libc/gdtoa/strtoIf.c58
-rw-r--r--lib/libc/gdtoa/strtoIg.c137
-rw-r--r--lib/libc/gdtoa/strtoIx.c64
-rw-r--r--lib/libc/gdtoa/strtoIxL.c62
-rw-r--r--lib/libc/gdtoa/strtod.c43
-rw-r--r--lib/libc/gdtoa/strtodI.c167
-rw-r--r--lib/libc/gdtoa/strtodg.c111
-rw-r--r--lib/libc/gdtoa/strtodnrp.c87
-rw-r--r--lib/libc/gdtoa/strtof.c3
-rw-r--r--lib/libc/gdtoa/strtopQ.c106
-rw-r--r--lib/libc/gdtoa/strtopd.c54
-rw-r--r--lib/libc/gdtoa/strtopdd.c183
-rw-r--r--lib/libc/gdtoa/strtopf.c78
-rw-r--r--lib/libc/gdtoa/strtopx.c108
-rw-r--r--lib/libc/gdtoa/strtopxL.c96
-rw-r--r--lib/libc/gdtoa/strtorQ.c3
-rw-r--r--lib/libc/gdtoa/strtord.c3
-rw-r--r--lib/libc/gdtoa/strtordd.c199
-rw-r--r--lib/libc/gdtoa/strtorf.c89
-rw-r--r--lib/libc/gdtoa/strtorx.c3
-rw-r--r--lib/libc/gdtoa/strtorxL.c107
-rw-r--r--lib/libc/gdtoa/sum.c4
-rw-r--r--lib/libc/stdio/vfprintf.c18
-rw-r--r--lib/libc/stdlib/ecvt.c4
-rw-r--r--lib/libc/stdlib/gcvt.c4
46 files changed, 408 insertions, 2989 deletions
diff --git a/lib/libc/arch/vax/gdtoa/strtof.c b/lib/libc/arch/vax/gdtoa/strtof.c
index 7ae20c2f894..11105f0effd 100644
--- a/lib/libc/arch/vax/gdtoa/strtof.c
+++ b/lib/libc/arch/vax/gdtoa/strtof.c
@@ -65,6 +65,10 @@ strtof(CONST char *s, char **sp)
case STRTOG_Infinite:
u.L[0] = 0xffff7fff;
break;
+
+ case STRTOG_NoMemory:
+ errno = ERANGE;
+ return (HUGE_VALF);
}
if (k & STRTOG_Neg)
u.L[0] |= 0x00008000L;
diff --git a/lib/libc/gdtoa/arithchk.c b/lib/libc/gdtoa/arithchk.c
deleted file mode 100644
index 3211aeda42c..00000000000
--- a/lib/libc/gdtoa/arithchk.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/****************************************************************
-Copyright (C) 1997, 1998 Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-****************************************************************/
-
-/* Try to deduce arith.h from arithmetic properties. */
-
-#include <stdio.h>
-
- static int dalign;
- typedef struct
-Akind {
- char *name;
- int kind;
- } Akind;
-
- static Akind
-IEEE_8087 = { "IEEE_8087", 1 },
-IEEE_MC68k = { "IEEE_MC68k", 2 },
-IBM = { "IBM", 3 },
-VAX = { "VAX", 4 },
-CRAY = { "CRAY", 5};
-
- static Akind *
-Lcheck()
-{
- union {
- double d;
- long L[2];
- } u;
- struct {
- double d;
- long L;
- } x[2];
-
- if (sizeof(x) > 2*(sizeof(double) + sizeof(long)))
- dalign = 1;
- u.L[0] = u.L[1] = 0;
- u.d = 1e13;
- if (u.L[0] == 1117925532 && u.L[1] == -448790528)
- return &IEEE_MC68k;
- if (u.L[1] == 1117925532 && u.L[0] == -448790528)
- return &IEEE_8087;
- if (u.L[0] == -2065213935 && u.L[1] == 10752)
- return &VAX;
- if (u.L[0] == 1267827943 && u.L[1] == 704643072)
- return &IBM;
- return 0;
- }
-
- static Akind *
-icheck()
-{
- union {
- double d;
- int L[2];
- } u;
- struct {
- double d;
- int L;
- } x[2];
-
- if (sizeof(x) > 2*(sizeof(double) + sizeof(int)))
- dalign = 1;
- u.L[0] = u.L[1] = 0;
- u.d = 1e13;
- if (u.L[0] == 1117925532 && u.L[1] == -448790528)
- return &IEEE_MC68k;
- if (u.L[1] == 1117925532 && u.L[0] == -448790528)
- return &IEEE_8087;
- if (u.L[0] == -2065213935 && u.L[1] == 10752)
- return &VAX;
- if (u.L[0] == 1267827943 && u.L[1] == 704643072)
- return &IBM;
- return 0;
- }
-
-char *emptyfmt = ""; /* avoid possible warning message with printf("") */
-
- static Akind *
-ccheck()
-{
- union {
- double d;
- long L;
- } u;
- long Cray1;
-
- /* Cray1 = 4617762693716115456 -- without overflow on non-Crays */
- Cray1 = printf(emptyfmt) < 0 ? 0 : 4617762;
- if (printf(emptyfmt, Cray1) >= 0)
- Cray1 = 1000000*Cray1 + 693716;
- if (printf(emptyfmt, Cray1) >= 0)
- Cray1 = 1000000*Cray1 + 115456;
- u.d = 1e13;
- if (u.L == Cray1)
- return &CRAY;
- return 0;
- }
-
- static int
-fzcheck()
-{
- double a, b;
- int i;
-
- a = 1.;
- b = .1;
- for(i = 155;; b *= b, i >>= 1) {
- if (i & 1) {
- a *= b;
- if (i == 1)
- break;
- }
- }
- b = a * a;
- return b == 0.;
- }
-
- int
-main()
-{
- Akind *a = 0;
- int Ldef = 0;
- FILE *f;
-
-#ifdef WRITE_ARITH_H /* for Symantec's buggy "make" */
- f = fopen("arith.h", "w");
- if (!f) {
- printf("Cannot open arith.h\n");
- return 1;
- }
-#else
- f = stdout;
-#endif
-
- if (sizeof(double) == 2*sizeof(long))
- a = Lcheck();
- else if (sizeof(double) == 2*sizeof(int)) {
- Ldef = 1;
- a = icheck();
- }
- else if (sizeof(double) == sizeof(long))
- a = ccheck();
- if (a) {
- fprintf(f, "#define %s\n#define Arith_Kind_ASL %d\n",
- a->name, a->kind);
- if (Ldef)
- fprintf(f, "#define Long int\n#define Intcast (int)(long)\n");
- if (dalign)
- fprintf(f, "#define Double_Align\n");
- if (sizeof(char*) == 8)
- fprintf(f, "#define X64_bit_pointers\n");
-#ifndef NO_LONG_LONG
- if (sizeof(long long) < 8)
-#endif
- fprintf(f, "#define NO_LONG_LONG\n");
- if (a->kind <= 2 && fzcheck())
- fprintf(f, "#define Sudden_Underflow\n");
- return 0;
- }
- fprintf(f, "/* Unknown arithmetic */\n");
- return 1;
- }
diff --git a/lib/libc/gdtoa/dmisc.c b/lib/libc/gdtoa/dmisc.c
index ce170c733bf..585cbfc9a56 100644
--- a/lib/libc/gdtoa/dmisc.c
+++ b/lib/libc/gdtoa/dmisc.c
@@ -50,6 +50,12 @@ rv_alloc(int i)
j <<= 1)
k++;
r = (int*)Balloc(k);
+ if (r == NULL)
+ return (
+#ifndef MULTIPLE_THREADS
+ dtoa_result =
+#endif
+ NULL);
*r = k;
return
#ifndef MULTIPLE_THREADS
@@ -68,6 +74,8 @@ nrv_alloc(char *s, char **rve, int n)
char *rv, *t;
t = rv = rv_alloc(n);
+ if (t == NULL)
+ return NULL;
while((*t = *s++) !=0)
t++;
if (rve)
diff --git a/lib/libc/gdtoa/dtoa.c b/lib/libc/gdtoa/dtoa.c
index 48fdf5efc2d..89ab53137b2 100644
--- a/lib/libc/gdtoa/dtoa.c
+++ b/lib/libc/gdtoa/dtoa.c
@@ -197,6 +197,8 @@ dtoa
#endif
b = d2b(dval(d), &be, &bbits);
+ if (b == NULL)
+ return NULL;
#ifdef Sudden_Underflow
i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
#else
@@ -323,6 +325,8 @@ dtoa
i = 1;
}
s = s0 = rv_alloc(i);
+ if (s == NULL)
+ return (NULL);
#ifdef Honor_FLT_ROUNDS
if (mode > 1 && Rounding != 1)
@@ -500,6 +504,8 @@ dtoa
b2 += i;
s2 += i;
mhi = i2b(1);
+ if (mhi == NULL)
+ return (NULL);
}
if (m2 > 0 && s2 > 0) {
i = m2 < s2 ? m2 : s2;
@@ -511,19 +517,34 @@ dtoa
if (leftright) {
if (m5 > 0) {
mhi = pow5mult(mhi, m5);
+ if (mhi == NULL)
+ return (NULL);
b1 = mult(mhi, b);
+ if (b1 == NULL)
+ return (NULL);
Bfree(b);
b = b1;
}
- if (( j = b5 - m5 )!=0)
+ if (( j = b5 - m5 )!=0) {
b = pow5mult(b, j);
+ if (b == NULL)
+ return (NULL);
}
- else
+ }
+ else {
b = pow5mult(b, b5);
+ if (b == NULL)
+ return (NULL);
+ }
}
S = i2b(1);
- if (s5 > 0)
+ if (S == NULL)
+ return (NULL);
+ if (s5 > 0) {
S = pow5mult(S, s5);
+ if (S == NULL)
+ return (NULL);
+ }
/* Check for special case that d is a normalized power of 2. */
@@ -571,21 +592,35 @@ dtoa
m2 += i;
s2 += i;
}
- if (b2 > 0)
+ if (b2 > 0) {
b = lshift(b, b2);
- if (s2 > 0)
+ if (b == NULL)
+ return (NULL);
+ }
+ if (s2 > 0) {
S = lshift(S, s2);
+ if (S == NULL)
+ return (NULL);
+ }
if (k_check) {
if (cmp(b,S) < 0) {
k--;
b = multadd(b, 10, 0); /* we botched the k estimate */
- if (leftright)
+ if (b == NULL)
+ return (NULL);
+ if (leftright) {
mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return (NULL);
+ }
ilim = ilim1;
}
}
if (ilim <= 0 && (mode == 3 || mode == 5)) {
- if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+ S = multadd(S, 5, 0);
+ if (S == NULL)
+ return (NULL);
+ if (ilim < 0 || cmp(b, S) <= 0) {
/* no digits, fcvt style */
no_digits:
k = -1 - ndigits;
@@ -597,8 +632,11 @@ dtoa
goto ret;
}
if (leftright) {
- if (m2 > 0)
+ if (m2 > 0) {
mhi = lshift(mhi, m2);
+ if (mhi == NULL)
+ return (NULL);
+ }
/* Compute mlo -- check for special case
* that d is a normalized power of 2.
@@ -607,8 +645,12 @@ dtoa
mlo = mhi;
if (spec_case) {
mhi = Balloc(mhi->k);
+ if (mhi == NULL)
+ return (NULL);
Bcopy(mhi, mlo);
mhi = lshift(mhi, Log2P);
+ if (mhi == NULL)
+ return (NULL);
}
for(i = 1;;i++) {
@@ -618,6 +660,8 @@ dtoa
*/
j = cmp(b, mlo);
delta = diff(S, mhi);
+ if (delta == NULL)
+ return (NULL);
j1 = delta->sign ? 1 : cmp(b, delta);
Bfree(delta);
#ifndef ROUND_BIASED
@@ -658,6 +702,8 @@ dtoa
#endif /*Honor_FLT_ROUNDS*/
if (j1 > 0) {
b = lshift(b, 1);
+ if (b == NULL)
+ return (NULL);
j1 = cmp(b, S);
if ((j1 > 0 || j1 == 0 && dig & 1)
&& dig++ == '9')
@@ -687,11 +733,20 @@ dtoa
if (i == ilim)
break;
b = multadd(b, 10, 0);
- if (mlo == mhi)
+ if (b == NULL)
+ return (NULL);
+ if (mlo == mhi) {
mlo = mhi = multadd(mhi, 10, 0);
+ if (mlo == NULL)
+ return (NULL);
+ }
else {
mlo = multadd(mlo, 10, 0);
+ if (mlo == NULL)
+ return (NULL);
mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return (NULL);
}
}
}
@@ -707,6 +762,8 @@ dtoa
if (i >= ilim)
break;
b = multadd(b, 10, 0);
+ if (b == NULL)
+ return (NULL);
}
/* Round off last digit */
@@ -718,6 +775,8 @@ dtoa
}
#endif
b = lshift(b, 1);
+ if (b == NULL)
+ return (NULL);
j = cmp(b, S);
if (j > 0 || j == 0 && dig & 1) {
roundoff:
diff --git a/lib/libc/gdtoa/g_Qfmt.c b/lib/libc/gdtoa/g_Qfmt.c
deleted file mode 100644
index 15d1bdde459..00000000000
--- a/lib/libc/gdtoa/g_Qfmt.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#define _3 3
-#endif
-#ifdef IEEE_8087
-#define _0 3
-#define _1 2
-#define _2 1
-#define _3 0
-#endif
-
- char*
-#ifdef KR_headers
-g_Qfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize;
-#else
-g_Qfmt(char *buf, void *V, int ndig, size_t bufsize)
-#endif
-{
- static FPI fpi0 = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 };
- char *b, *s, *se;
- ULong bits[4], *L, sign;
- int decpt, ex, i, mode;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- if (ndig < 0)
- ndig = 0;
- if (bufsize < ndig + 10)
- return 0;
-
- L = (ULong*)V;
- sign = L[_0] & 0x80000000L;
- bits[3] = L[_0] & 0xffff;
- bits[2] = L[_1];
- bits[1] = L[_2];
- bits[0] = L[_3];
- b = buf;
- if ( (ex = (L[_0] & 0x7fff0000L) >> 16) !=0) {
- if (ex == 0x7fff) {
- /* Infinity or NaN */
- if (bits[0] | bits[1] | bits[2] | bits[3])
- b = strcp(b, "NaN");
- else {
- b = buf;
- if (sign)
- *b++ = '-';
- b = strcp(b, "Infinity");
- }
- return b;
- }
- i = STRTOG_Normal;
- bits[3] |= 0x10000;
- }
- else if (bits[0] | bits[1] | bits[2] | bits[3]) {
- i = STRTOG_Denormal;
- ex = 1;
- }
- else {
-#ifndef IGNORE_ZERO_SIGN
- if (sign)
- *b++ = '-';
-#endif
- *b++ = '0';
- *b = 0;
- return b;
- }
- ex -= 0x3fff + 112;
- mode = 2;
- if (ndig <= 0) {
- if (bufsize < 48)
- return 0;
- mode = 0;
- }
- s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- return g__fmt(buf, s, se, decpt, sign, bufsize);
- }
diff --git a/lib/libc/gdtoa/g__fmt.c b/lib/libc/gdtoa/g__fmt.c
deleted file mode 100644
index 3eeb1bce962..00000000000
--- a/lib/libc/gdtoa/g__fmt.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#ifdef USE_LOCALE
-#include "locale.h"
-#endif
-
- char *
-#ifdef KR_headers
-g__fmt(b, s, se, decpt, sign, blen) char *b; char *s; char *se; int decpt; ULong sign; size_t blen;
-#else
-g__fmt(char *b, char *s, char *se, int decpt, ULong sign, size_t blen)
-#endif
-{
- int i, j, k;
- char *be, *s0;
- size_t len;
-#ifdef USE_LOCALE
-#ifdef NO_LOCALE_CACHE
- char *decimalpoint = localeconv()->decimal_point;
- size_t dlen = strlen(decimalpoint);
-#else
- char *decimalpoint;
- static char *decimalpoint_cache;
- static size_t dlen;
- if (!(s0 = decimalpoint_cache)) {
- s0 = localeconv()->decimal_point;
- dlen = strlen(s0);
- if ((decimalpoint_cache = (char*)malloc(dlen + 1))) {
- strlcpy(decimalpoint_cache, s0, dlen + 1);
- s0 = decimalpoint_cache;
- }
- }
- decimalpoint = s0;
-#endif
-#else
-#define dlen 0
-#endif
- s0 = s;
- len = (se-s) + dlen + 6; /* 6 = sign + e+dd + trailing null */
- if (blen < len)
- goto ret0;
- be = b + blen - 1;
- if (sign)
- *b++ = '-';
- if (decpt <= -4 || decpt > se - s + 5) {
- *b++ = *s++;
- if (*s) {
-#ifdef USE_LOCALE
- while((*b = *decimalpoint++))
- ++b;
-#else
- *b++ = '.';
-#endif
- while((*b = *s++) !=0)
- b++;
- }
- *b++ = 'e';
- /* sprintf(b, "%+.2d", decpt - 1); */
- if (--decpt < 0) {
- *b++ = '-';
- decpt = -decpt;
- }
- else
- *b++ = '+';
- for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10){}
- for(;;) {
- i = decpt / k;
- if (b >= be)
- goto ret0;
- *b++ = i + '0';
- if (--j <= 0)
- break;
- decpt -= i*k;
- decpt *= 10;
- }
- *b = 0;
- }
- else if (decpt <= 0) {
-#ifdef USE_LOCALE
- while((*b = *decimalpoint++))
- ++b;
-#else
- *b++ = '.';
-#endif
- if (be < b - decpt + (se - s))
- goto ret0;
- for(; decpt < 0; decpt++)
- *b++ = '0';
- while((*b = *s++) != 0)
- b++;
- }
- else {
- while((*b = *s++) != 0) {
- b++;
- if (--decpt == 0 && *s) {
-#ifdef USE_LOCALE
- while(*b = *decimalpoint++)
- ++b;
-#else
- *b++ = '.';
-#endif
- }
- }
- if (b + decpt > be) {
- ret0:
- b = 0;
- goto ret;
- }
- for(; decpt > 0; decpt--)
- *b++ = '0';
- *b = 0;
- }
- ret:
- freedtoa(s0);
- return b;
- }
diff --git a/lib/libc/gdtoa/g_ddfmt.c b/lib/libc/gdtoa/g_ddfmt.c
deleted file mode 100644
index b65d39d793c..00000000000
--- a/lib/libc/gdtoa/g_ddfmt.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg@acm.org). */
-
-#include "gdtoaimp.h"
-#include <string.h>
-
- char *
-#ifdef KR_headers
-g_ddfmt(buf, dd, ndig, bufsize) char *buf; double *dd; int ndig; size_t bufsize;
-#else
-g_ddfmt(char *buf, double *dd, int ndig, size_t bufsize)
-#endif
-{
- FPI fpi;
- char *b, *s, *se;
- ULong *L, bits0[4], *bits, *zx;
- int bx, by, decpt, ex, ey, i, j, mode;
- Bigint *x, *y, *z;
- double ddx[2];
-#ifdef Honor_FLT_ROUNDS /*{{*/
- int Rounding;
-#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
- Rounding = Flt_Rounds;
-#else /*}{*/
- Rounding = 1;
- switch(fegetround()) {
- case FE_TOWARDZERO: Rounding = 0; break;
- case FE_UPWARD: Rounding = 2; break;
- case FE_DOWNWARD: Rounding = 3;
- }
-#endif /*}}*/
-#else /*}{*/
-#define Rounding FPI_Round_near
-#endif /*}}*/
-
- if (bufsize < 10 || bufsize < ndig + 8)
- return 0;
-
- L = (ULong*)dd;
- if ((L[_0] & 0x7ff00000L) == 0x7ff00000L) {
- /* Infinity or NaN */
- if (L[_0] & 0xfffff || L[_1]) {
- nanret:
- return strcp(buf, "NaN");
- }
- if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) {
- if (L[2+_0] & 0xfffff || L[2+_1])
- goto nanret;
- if ((L[_0] ^ L[2+_0]) & 0x80000000L)
- goto nanret; /* Infinity - Infinity */
- }
- infret:
- b = buf;
- if (L[_0] & 0x80000000L)
- *b++ = '-';
- return strcp(b, "Infinity");
- }
- if ((L[2+_0] & 0x7ff00000) == 0x7ff00000) {
- L += 2;
- if (L[_0] & 0xfffff || L[_1])
- goto nanret;
- goto infret;
- }
- if (dd[0] + dd[1] == 0.) {
- b = buf;
-#ifndef IGNORE_ZERO_SIGN
- if (L[_0] & L[2+_0] & 0x80000000L)
- *b++ = '-';
-#endif
- *b++ = '0';
- *b = 0;
- return b;
- }
- if ((L[_0] & 0x7ff00000L) < (L[2+_0] & 0x7ff00000L)) {
- ddx[1] = dd[0];
- ddx[0] = dd[1];
- dd = ddx;
- L = (ULong*)dd;
- }
- z = d2b(dd[0], &ex, &bx);
- if (dd[1] == 0.)
- goto no_y;
- x = z;
- y = d2b(dd[1], &ey, &by);
- if ( (i = ex - ey) !=0) {
- if (i > 0) {
- x = lshift(x, i);
- ex = ey;
- }
- else
- y = lshift(y, -i);
- }
- if ((L[_0] ^ L[2+_0]) & 0x80000000L) {
- z = diff(x, y);
- if (L[_0] & 0x80000000L)
- z->sign = 1 - z->sign;
- }
- else {
- z = sum(x, y);
- if (L[_0] & 0x80000000L)
- z->sign = 1;
- }
- Bfree(x);
- Bfree(y);
- no_y:
- bits = zx = z->x;
- for(i = 0; !*zx; zx++)
- i += 32;
- i += lo0bits(zx);
- if (i) {
- rshift(z, i);
- ex += i;
- }
- fpi.nbits = z->wds * 32 - hi0bits(z->x[j = z->wds-1]);
- if (fpi.nbits < 106) {
- fpi.nbits = 106;
- if (j < 3) {
- for(i = 0; i <= j; i++)
- bits0[i] = bits[i];
- while(i < 4)
- bits0[i++] = 0;
- bits = bits0;
- }
- }
- mode = 2;
- if (ndig <= 0) {
- if (bufsize < (int)(fpi.nbits * .301029995664) + 10) {
- Bfree(z);
- return 0;
- }
- mode = 0;
- }
- fpi.emin = 1-1023-53+1;
- fpi.emax = 2046-1023-106+1;
- fpi.rounding = Rounding;
- fpi.sudden_underflow = 0;
- i = STRTOG_Normal;
- s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- b = g__fmt(buf, s, se, decpt, z->sign, bufsize);
- Bfree(z);
- return b;
- }
diff --git a/lib/libc/gdtoa/g_dfmt.c b/lib/libc/gdtoa/g_dfmt.c
deleted file mode 100644
index 23d8b2470f4..00000000000
--- a/lib/libc/gdtoa/g_dfmt.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- char*
-#ifdef KR_headers
-g_dfmt(buf, d, ndig, bufsize) char *buf; double *d; int ndig; size_t bufsize;
-#else
-g_dfmt(char *buf, double *d, int ndig, size_t bufsize)
-#endif
-{
- static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, 0 };
- char *b, *s, *se;
- ULong bits[2], *L, sign;
- int decpt, ex, i, mode;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- if (ndig < 0)
- ndig = 0;
- if (bufsize < ndig + 10)
- return 0;
-
- L = (ULong*)d;
- sign = L[_0] & 0x80000000L;
- if ((L[_0] & 0x7ff00000) == 0x7ff00000) {
- /* Infinity or NaN */
- if (bufsize < 10)
- return 0;
- if (L[_0] & 0xfffff || L[_1]) {
- return strcp(buf, "NaN");
- }
- b = buf;
- if (sign)
- *b++ = '-';
- return strcp(b, "Infinity");
- }
- if (L[_1] == 0 && (L[_0] ^ sign) == 0 /*d == 0.*/) {
- b = buf;
-#ifndef IGNORE_ZERO_SIGN
- if (L[_0] & 0x80000000L)
- *b++ = '-';
-#endif
- *b++ = '0';
- *b = 0;
- return b;
- }
- bits[0] = L[_1];
- bits[1] = L[_0] & 0xfffff;
- if ( (ex = (L[_0] >> 20) & 0x7ff) !=0)
- bits[1] |= 0x100000;
- else
- ex = 1;
- ex -= 0x3ff + 52;
- mode = 2;
- if (ndig <= 0)
- mode = 0;
- i = STRTOG_Normal;
- s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- return g__fmt(buf, s, se, decpt, sign, bufsize);
- }
diff --git a/lib/libc/gdtoa/g_ffmt.c b/lib/libc/gdtoa/g_ffmt.c
deleted file mode 100644
index 1c27c602b22..00000000000
--- a/lib/libc/gdtoa/g_ffmt.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- char*
-#ifdef KR_headers
-g_ffmt(buf, f, ndig, bufsize) char *buf; float *f; int ndig; size_t bufsize;
-#else
-g_ffmt(char *buf, float *f, int ndig, size_t bufsize)
-#endif
-{
- static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, 0 };
- char *b, *s, *se;
- ULong bits[1], *L, sign;
- int decpt, ex, i, mode;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- if (ndig < 0)
- ndig = 0;
- if (bufsize < ndig + 10)
- return 0;
-
- L = (ULong*)f;
- sign = L[0] & 0x80000000L;
- if ((L[0] & 0x7f800000) == 0x7f800000) {
- /* Infinity or NaN */
- if (L[0] & 0x7fffff) {
- return strcp(buf, "NaN");
- }
- b = buf;
- if (sign)
- *b++ = '-';
- return strcp(b, "Infinity");
- }
- if (*f == 0.) {
- b = buf;
-#ifndef IGNORE_ZERO_SIGN
- if (L[0] & 0x80000000L)
- *b++ = '-';
-#endif
- *b++ = '0';
- *b = 0;
- return b;
- }
- bits[0] = L[0] & 0x7fffff;
- if ( (ex = (L[0] >> 23) & 0xff) !=0)
- bits[0] |= 0x800000;
- else
- ex = 1;
- ex -= 0x7f + 23;
- mode = 2;
- if (ndig <= 0) {
- if (bufsize < 16)
- return 0;
- mode = 0;
- }
- i = STRTOG_Normal;
- s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- return g__fmt(buf, s, se, decpt, sign, bufsize);
- }
diff --git a/lib/libc/gdtoa/g_xLfmt.c b/lib/libc/gdtoa/g_xLfmt.c
deleted file mode 100644
index 6fa1de2dad6..00000000000
--- a/lib/libc/gdtoa/g_xLfmt.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#endif
-#ifdef IEEE_8087
-#define _0 2
-#define _1 1
-#define _2 0
-#endif
-
- char*
-#ifdef KR_headers
-g_xLfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize;
-#else
-g_xLfmt(char *buf, void *V, int ndig, size_t bufsize)
-#endif
-{
- static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };
- char *b, *s, *se;
- ULong bits[2], *L, sign;
- int decpt, ex, i, mode;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- if (ndig < 0)
- ndig = 0;
- if (bufsize < ndig + 10)
- return 0;
-
- L = (ULong*)V;
- sign = L[_0] & 0x80000000L;
- bits[1] = L[_1];
- bits[0] = L[_2];
- if ( (ex = (L[_0] >> 16) & 0x7fff) !=0) {
- if (ex == 0x7fff) {
- /* Infinity or NaN */
- if (bits[0] | bits[1])
- b = strcp(buf, "NaN");
- else {
- b = buf;
- if (sign)
- *b++ = '-';
- b = strcp(b, "Infinity");
- }
- return b;
- }
- i = STRTOG_Normal;
- }
- else if (bits[0] | bits[1]) {
- i = STRTOG_Denormal;
- }
- else {
- b = buf;
-#ifndef IGNORE_ZERO_SIGN
- if (sign)
- *b++ = '-';
-#endif
- *b++ = '0';
- *b = 0;
- return b;
- }
- ex -= 0x3fff + 63;
- mode = 2;
- if (ndig <= 0) {
- if (bufsize < 32)
- return 0;
- mode = 0;
- }
- s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- return g__fmt(buf, s, se, decpt, sign, bufsize);
- }
diff --git a/lib/libc/gdtoa/g_xfmt.c b/lib/libc/gdtoa/g_xfmt.c
deleted file mode 100644
index 495c7b471e7..00000000000
--- a/lib/libc/gdtoa/g_xfmt.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#define _3 3
-#define _4 4
-#endif
-#ifdef IEEE_8087
-#define _0 4
-#define _1 3
-#define _2 2
-#define _3 1
-#define _4 0
-#endif
-
- char*
-#ifdef KR_headers
-g_xfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize;
-#else
-g_xfmt(char *buf, void *V, int ndig, size_t bufsize)
-#endif
-{
- static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };
- char *b, *s, *se;
- ULong bits[2], sign;
- UShort *L;
- int decpt, ex, i, mode;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- if (ndig < 0)
- ndig = 0;
- if (bufsize < ndig + 10)
- return 0;
-
- L = (UShort *)V;
- sign = L[_0] & 0x8000;
- bits[1] = (L[_1] << 16) | L[_2];
- bits[0] = (L[_3] << 16) | L[_4];
- if ( (ex = L[_0] & 0x7fff) !=0) {
- if (ex == 0x7fff) {
- /* Infinity or NaN */
- if (bits[0] | bits[1])
- b = strcp(buf, "NaN");
- else {
- b = buf;
- if (sign)
- *b++ = '-';
- b = strcp(b, "Infinity");
- }
- return b;
- }
- i = STRTOG_Normal;
- }
- else if (bits[0] | bits[1]) {
- i = STRTOG_Denormal;
- ex = 1;
- }
- else {
- b = buf;
-#ifndef IGNORE_ZERO_SIGN
- if (sign)
- *b++ = '-';
-#endif
- *b++ = '0';
- *b = 0;
- return b;
- }
- ex -= 0x3fff + 63;
- mode = 2;
- if (ndig <= 0) {
- if (bufsize < 32)
- return 0;
- mode = 0;
- }
- s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);
- return g__fmt(buf, s, se, decpt, sign, bufsize);
- }
diff --git a/lib/libc/gdtoa/gdtoa.c b/lib/libc/gdtoa/gdtoa.c
index 3b642508fe9..33c5adf4c48 100644
--- a/lib/libc/gdtoa/gdtoa.c
+++ b/lib/libc/gdtoa/gdtoa.c
@@ -53,6 +53,8 @@ bitstob(ULong *bits, int nbits, int *bbits)
k = 1;
#endif
b = Balloc(k);
+ if (b == NULL)
+ return (NULL);
be = bits + ((nbits - 1) >> kshift);
x = x0 = b->x;
do {
@@ -184,6 +186,8 @@ gdtoa
return 0;
}
b = bitstob(bits, nbits = fpi->nbits, &bbits);
+ if (b == NULL)
+ return (NULL);
be0 = be;
if ( (i = trailz(b)) !=0) {
rshift(b, i);
@@ -309,6 +313,8 @@ gdtoa
i = 1;
}
s = s0 = rv_alloc(i);
+ if (s == NULL)
+ return (NULL);
if ( (rdir = fpi->rounding - 1) !=0) {
if (rdir < 0)
@@ -516,6 +522,8 @@ gdtoa
b2 += i;
s2 += i;
mhi = i2b(1);
+ if (mhi == NULL)
+ return (NULL);
}
if (m2 > 0 && s2 > 0) {
i = m2 < s2 ? m2 : s2;
@@ -527,19 +535,34 @@ gdtoa
if (leftright) {
if (m5 > 0) {
mhi = pow5mult(mhi, m5);
+ if (mhi == NULL)
+ return (NULL);
b1 = mult(mhi, b);
+ if (b1 == NULL)
+ return (NULL);
Bfree(b);
b = b1;
}
- if ( (j = b5 - m5) !=0)
+ if ( (j = b5 - m5) !=0) {
b = pow5mult(b, j);
+ if (b == NULL)
+ return (NULL);
}
- else
+ }
+ else {
b = pow5mult(b, b5);
+ if (b == NULL)
+ return (NULL);
+ }
}
S = i2b(1);
- if (s5 > 0)
+ if (S == NULL)
+ return (NULL);
+ if (s5 > 0) {
S = pow5mult(S, s5);
+ if (S == NULL)
+ return (NULL);
+ }
/* Check for special case that d is a normalized power of 2. */
@@ -579,21 +602,35 @@ gdtoa
m2 += i;
s2 += i;
}
- if (b2 > 0)
+ if (b2 > 0) {
b = lshift(b, b2);
- if (s2 > 0)
+ if (b == NULL)
+ return (NULL);
+ }
+ if (s2 > 0) {
S = lshift(S, s2);
+ if (S == NULL)
+ return (NULL);
+ }
if (k_check) {
if (cmp(b,S) < 0) {
k--;
b = multadd(b, 10, 0); /* we botched the k estimate */
- if (leftright)
+ if (b == NULL)
+ return (NULL);
+ if (leftright) {
mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return (NULL);
+ }
ilim = ilim1;
}
}
if (ilim <= 0 && mode > 2) {
- if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+ S = multadd(S, 5, 0);
+ if (S == NULL)
+ return (NULL);
+ if (ilim < 0 || cmp(b, S) <= 0) {
/* no digits, fcvt style */
no_digits:
k = -1 - ndigits;
@@ -607,8 +644,11 @@ gdtoa
goto ret;
}
if (leftright) {
- if (m2 > 0)
+ if (m2 > 0) {
mhi = lshift(mhi, m2);
+ if (mhi == NULL)
+ return (NULL);
+ }
/* Compute mlo -- check for special case
* that d is a normalized power of 2.
@@ -617,8 +657,12 @@ gdtoa
mlo = mhi;
if (spec_case) {
mhi = Balloc(mhi->k);
+ if (mhi == NULL)
+ return (NULL);
Bcopy(mhi, mlo);
mhi = lshift(mhi, 1);
+ if (mhi == NULL)
+ return (NULL);
}
for(i = 1;;i++) {
@@ -628,6 +672,8 @@ gdtoa
*/
j = cmp(b, mlo);
delta = diff(S, mhi);
+ if (delta == NULL)
+ return (NULL);
j1 = delta->sign ? 1 : cmp(b, delta);
Bfree(delta);
#ifndef ROUND_BIASED
@@ -659,10 +705,14 @@ gdtoa
while (cmp(S,mhi) > 0) {
*s++ = dig;
mhi1 = multadd(mhi, 10, 0);
+ if (mhi1 == NULL)
+ return (NULL);
if (mlo == mhi)
mlo = mhi1;
mhi = mhi1;
b = multadd(b, 10, 0);
+ if (b == NULL)
+ return (NULL);
dig = quorem(b,S) + '0';
}
if (dig++ == '9')
@@ -672,6 +722,8 @@ gdtoa
}
if (j1 > 0) {
b = lshift(b, 1);
+ if (b == NULL)
+ return (NULL);
j1 = cmp(b, S);
if ((j1 > 0 || j1 == 0 && dig & 1)
&& dig++ == '9')
@@ -699,11 +751,20 @@ gdtoa
if (i == ilim)
break;
b = multadd(b, 10, 0);
- if (mlo == mhi)
+ if (b == NULL)
+ return (NULL);
+ if (mlo == mhi) {
mlo = mhi = multadd(mhi, 10, 0);
+ if (mlo == NULL)
+ return (NULL);
+ }
else {
mlo = multadd(mlo, 10, 0);
+ if (mlo == NULL)
+ return (NULL);
mhi = multadd(mhi, 10, 0);
+ if (mhi == NULL)
+ return (NULL);
}
}
}
@@ -713,6 +774,8 @@ gdtoa
if (i >= ilim)
break;
b = multadd(b, 10, 0);
+ if (b == NULL)
+ return (NULL);
}
/* Round off last digit */
@@ -723,6 +786,8 @@ gdtoa
goto roundoff;
}
b = lshift(b, 1);
+ if (b == NULL)
+ return (NULL);
j = cmp(b, S);
if (j > 0 || j == 0 && dig & 1) {
roundoff:
diff --git a/lib/libc/gdtoa/gdtoa.h b/lib/libc/gdtoa/gdtoa.h
index 3cd95292088..664b77e0ef6 100644
--- a/lib/libc/gdtoa/gdtoa.h
+++ b/lib/libc/gdtoa/gdtoa.h
@@ -64,23 +64,24 @@ typedef unsigned short UShort;
#endif /* CONST */
enum { /* return values from strtodg */
- STRTOG_Zero = 0,
- STRTOG_Normal = 1,
- STRTOG_Denormal = 2,
- STRTOG_Infinite = 3,
- STRTOG_NaN = 4,
- STRTOG_NaNbits = 5,
- STRTOG_NoNumber = 6,
- STRTOG_Retmask = 7,
+ STRTOG_Zero = 0x000,
+ STRTOG_Normal = 0x001,
+ STRTOG_Denormal = 0x002,
+ STRTOG_Infinite = 0x003,
+ STRTOG_NaN = 0x004,
+ STRTOG_NaNbits = 0x005,
+ STRTOG_NoNumber = 0x006,
+ STRTOG_NoMemory = 0x007,
+ STRTOG_Retmask = 0x00f,
/* The following may be or-ed into one of the above values. */
-
- STRTOG_Neg = 0x08, /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
- STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
- STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
- STRTOG_Inexact = 0x30,
- STRTOG_Underflow= 0x40,
- STRTOG_Overflow = 0x80
+ STRTOG_Inexlo = 0x010, /* returned result rounded toward zero */
+ STRTOG_Inexhi = 0x020, /* returned result rounded away from zero */
+ STRTOG_Inexact = 0x030,
+ STRTOG_Underflow= 0x040,
+ STRTOG_Overflow = 0x080,
+ STRTOG_Neg = 0x100 /* does not affect STRTOG_Inexlo or
+ * STRTOG_Inexhi */
};
typedef struct
diff --git a/lib/libc/gdtoa/gethex.c b/lib/libc/gdtoa/gethex.c
index d3027fbbcbf..b13599ddbdf 100644
--- a/lib/libc/gdtoa/gethex.c
+++ b/lib/libc/gdtoa/gethex.c
@@ -169,6 +169,8 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
goto retz;
ret_tiny:
b = Balloc(0);
+ if (b == NULL)
+ return (STRTOG_NoMemory);
b->wds = 1;
b->x[0] = 1;
goto dret;
@@ -192,6 +194,8 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
++n;
for(j = n, k = 0; j >>= 1; ++k);
*bp = b = Balloc(k);
+ if (b == NULL)
+ return (STRTOG_NoMemory);
b->wds = n;
for(j = 0; j < n0; ++j)
b->x[j] = ALL_ON;
@@ -204,6 +208,8 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
for(k = 0; n > 7; n >>= 1)
k++;
b = Balloc(k);
+ if (b == NULL)
+ return (STRTOG_NoMemory);
x = b->x;
n = 0;
L = 0;
@@ -251,6 +257,8 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
else if (n < nbits) {
n = nbits - n;
b = lshift(b, n);
+ if (b == NULL)
+ return (STRTOG_NoMemory);
e -= n;
x = b->x;
}
@@ -328,6 +336,8 @@ gethex( CONST char **sp, FPI *fpi, Long *exp, Bigint **bp, int sign)
if (up) {
k = b->wds;
b = increment(b);
+ if (b == NULL)
+ return (STRTOG_NoMemory);
x = b->x;
if (irv == STRTOG_Denormal) {
if (nbits == fpi->nbits - 1
diff --git a/lib/libc/gdtoa/hdtoa.c b/lib/libc/gdtoa/hdtoa.c
index f841538a300..c62f6d5d390 100644
--- a/lib/libc/gdtoa/hdtoa.c
+++ b/lib/libc/gdtoa/hdtoa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hdtoa.c,v 1.1 2008/09/07 20:36:08 martynas Exp $ */
+/* $OpenBSD: hdtoa.c,v 1.2 2009/10/16 12:15:03 martynas Exp $ */
/*-
* Copyright (c) 2004, 2005 David Schultz <das@FreeBSD.ORG>
* All rights reserved.
@@ -162,6 +162,8 @@ __hdtoa(double d, const char *xdigs, int ndigits, int *decpt, int *sign,
*/
bufsize = (sigfigs > ndigits) ? sigfigs : ndigits;
s0 = rv_alloc(bufsize);
+ if (s0 == NULL)
+ return (NULL);
/*
* We work from right to left, first adding any requested zero
@@ -257,6 +259,8 @@ __hldtoa(long double e, const char *xdigs, int ndigits, int *decpt, int *sign,
*/
bufsize = (sigfigs > ndigits) ? sigfigs : ndigits;
s0 = rv_alloc(bufsize);
+ if (s0 == NULL)
+ return (NULL);
/*
* We work from right to left, first adding any requested zero
diff --git a/lib/libc/gdtoa/misc.c b/lib/libc/gdtoa/misc.c
index 6fd48e65192..8c5817764a1 100644
--- a/lib/libc/gdtoa/misc.c
+++ b/lib/libc/gdtoa/misc.c
@@ -62,6 +62,8 @@ Balloc
x = 1 << k;
#ifdef Omit_Private_Memory
rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
+ if (rv == NULL)
+ return (NULL);
#else
len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
/sizeof(double);
@@ -69,8 +71,11 @@ Balloc
rv = (Bigint*)pmem_next;
pmem_next += len;
}
- else
+ else {
rv = (Bigint*)MALLOC(len*sizeof(double));
+ if (rv == NULL)
+ return (NULL);
+ }
#endif
rv->k = k;
rv->maxwds = x;
@@ -195,6 +200,8 @@ multadd
if (carry) {
if (wds >= b->maxwds) {
b1 = Balloc(b->k+1);
+ if (b1 == NULL)
+ return (NULL);
Bcopy(b1, b);
Bfree(b);
b = b1;
@@ -250,6 +257,8 @@ i2b
Bigint *b;
b = Balloc(1);
+ if (b == NULL)
+ return (NULL);
b->x[0] = i;
b->wds = 1;
return b;
@@ -288,6 +297,8 @@ mult
if (wc > a->maxwds)
k++;
c = Balloc(k);
+ if (c == NULL)
+ return (NULL);
for(x = c->x, xa = x + wc; x < xa; x++)
*x = 0;
xa = a->x;
@@ -379,8 +390,11 @@ pow5mult
int i;
static int p05[3] = { 5, 25, 125 };
- if ( (i = k & 3) !=0)
+ if ( (i = k & 3) !=0) {
b = multadd(b, p05[i-1], 0);
+ if (b == NULL)
+ return (NULL);
+ }
if (!(k >>= 2))
return b;
@@ -390,17 +404,23 @@ pow5mult
ACQUIRE_DTOA_LOCK(1);
if (!(p5 = p5s)) {
p5 = p5s = i2b(625);
+ if (p5 == NULL)
+ return (NULL);
p5->next = 0;
}
FREE_DTOA_LOCK(1);
#else
p5 = p5s = i2b(625);
+ if (p5 == NULL)
+ return (NULL);
p5->next = 0;
#endif
}
for(;;) {
if (k & 1) {
b1 = mult(b, p5);
+ if (b1 == NULL)
+ return (NULL);
Bfree(b);
b = b1;
}
@@ -411,11 +431,15 @@ pow5mult
ACQUIRE_DTOA_LOCK(1);
if (!(p51 = p5->next)) {
p51 = p5->next = mult(p5,p5);
+ if (p51 == NULL)
+ return (NULL);
p51->next = 0;
}
FREE_DTOA_LOCK(1);
#else
p51 = p5->next = mult(p5,p5);
+ if (p51 == NULL)
+ return (NULL);
p51->next = 0;
#endif
}
@@ -442,6 +466,8 @@ lshift
for(i = b->maxwds; n1 > i; i <<= 1)
k1++;
b1 = Balloc(k1);
+ if (b1 == NULL)
+ return (NULL);
x1 = b1->x;
for(i = 0; i < n; i++)
*x1++ = 0;
@@ -535,6 +561,8 @@ diff
i = cmp(a,b);
if (!i) {
c = Balloc(0);
+ if (c == NULL)
+ return (NULL);
c->wds = 1;
c->x[0] = 0;
return c;
@@ -548,6 +576,8 @@ diff
else
i = 0;
c = Balloc(a->k);
+ if (c == NULL)
+ return (NULL);
c->sign = i;
wa = a->wds;
xa = a->x;
@@ -703,6 +733,8 @@ d2b
#else
b = Balloc(2);
#endif
+ if (b == NULL)
+ return (NULL);
x = b->x;
z = d0 & Frac_mask;
diff --git a/lib/libc/gdtoa/qnan.c b/lib/libc/gdtoa/qnan.c
deleted file mode 100644
index 118e749216a..00000000000
--- a/lib/libc/gdtoa/qnan.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 2005 by David M. Gay
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and its
-documentation for any purpose and without fee is hereby granted,
-provided that the above copyright notice appear in all copies and that
-both that the copyright notice and this permission notice and warranty
-disclaimer appear in supporting documentation, and that the name of
-the author or any of his current or former employers not be used in
-advertising or publicity pertaining to distribution of the software
-without specific, written prior permission.
-
-THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
-NO EVENT SHALL THE AUTHOR OR ANY OF HIS CURRENT OR FORMER EMPLOYERS BE
-LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
-DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
-WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
-SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-/* Program to compute quiet NaNs of various precisions (float, */
-/* double, and perhaps long double) on the current system, */
-/* provided the system uses binary IEEE (P754) arithmetic. */
-/* Note that one system's quiet NaN may be a signaling NaN on */
-/* another system. The IEEE arithmetic standards (P754, P854) */
-/* do not specify how to distinguish signaling NaNs from quiet */
-/* ones, and this detail varies across systems. The computed */
-/* NaN values are encoded in #defines for values for an */
-/* unsigned 32-bit integer type, called Ulong below, and */
-/* (for long double) perhaps as unsigned short values. Once */
-/* upon a time, there were PC compilers for Intel CPUs that */
-/* had sizeof(long double) = 10. Are such compilers still */
-/* distributed? */
-
-#include <stdio.h>
-#include "arith.h"
-
-#ifndef Long
-#define Long long
-#endif
-
-typedef unsigned Long Ulong;
-
-#undef HAVE_IEEE
-#ifdef IEEE_8087
-#define _0 1
-#define _1 0
-#define HAVE_IEEE
-#endif
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define HAVE_IEEE
-#endif
-
-#define UL (unsigned long)
-
- int
-main(void)
-{
-#ifdef HAVE_IEEE
- typedef union {
- float f;
- double d;
- Ulong L[4];
-#ifndef NO_LONG_LONG
- unsigned short u[5];
- long double D;
-#endif
- } U;
- U a, b, c;
- int i;
-
- a.L[0] = b.L[0] = 0x7f800000;
- c.f = a.f - b.f;
- printf("#define f_QNAN 0x%lx\n", UL c.L[0]);
- a.L[_0] = b.L[_0] = 0x7ff00000;
- a.L[_1] = b.L[_1] = 0;
- c.d = a.d - b.d; /* quiet NaN */
- printf("#define d_QNAN0 0x%lx\n", UL c.L[0]);
- printf("#define d_QNAN1 0x%lx\n", UL c.L[1]);
-#ifdef NO_LONG_LONG
- for(i = 0; i < 4; i++)
- printf("#define ld_QNAN%d 0xffffffff\n", i);
- for(i = 0; i < 5; i++)
- printf("#define ldus_QNAN%d 0xffff\n", i);
-#else
- b.D = c.D = a.d;
- if (printf("") < 0)
- c.D = 37; /* never executed; just defeat optimization */
- a.L[2] = a.L[3] = 0;
- a.D = b.D - c.D;
- for(i = 0; i < 4; i++)
- printf("#define ld_QNAN%d 0x%lx\n", i, UL a.L[i]);
- for(i = 0; i < 5; i++)
- printf("#define ldus_QNAN%d 0x%x\n", i, a.u[i]);
-#endif
-#endif /* HAVE_IEEE */
- return 0;
- }
diff --git a/lib/libc/gdtoa/smisc.c b/lib/libc/gdtoa/smisc.c
index 163011e0aa2..6cb9d4414fa 100644
--- a/lib/libc/gdtoa/smisc.c
+++ b/lib/libc/gdtoa/smisc.c
@@ -47,10 +47,14 @@ s2b
for(k = 0, y = 1; x > y; y <<= 1, k++) ;
#ifdef Pack_32
b = Balloc(k);
+ if (b == NULL)
+ return (NULL);
b->x[0] = y9;
b->wds = 1;
#else
b = Balloc(k+1);
+ if (b == NULL)
+ return (NULL);
b->x[0] = y9 & 0xffff;
b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
#endif
@@ -58,14 +62,20 @@ s2b
i = 9;
if (9 < nd0) {
s += 9;
- do b = multadd(b, 10, *s++ - '0');
- while(++i < nd0);
+ do {
+ b = multadd(b, 10, *s++ - '0');
+ if (b == NULL)
+ return (NULL);
+ } while(++i < nd0);
s++;
}
else
s += 10;
- for(; i < nd; i++)
+ for(; i < nd; i++) {
b = multadd(b, 10, *s++ - '0');
+ if (b == NULL)
+ return (NULL);
+ }
return b;
}
diff --git a/lib/libc/gdtoa/strtoIQ.c b/lib/libc/gdtoa/strtoIQ.c
deleted file mode 100644
index 9ce5120e6b7..00000000000
--- a/lib/libc/gdtoa/strtoIQ.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoIQ(s, sp, a, b) CONST char *s; char **sp; void *a; void *b;
-#else
-strtoIQ(CONST char *s, char **sp, void *a, void *b)
-#endif
-{
- static FPI fpi = { 113, 1-16383-113+1, 32766-16383-113+1, 1, SI };
- Long exp[2];
- Bigint *B[2];
- int k, rv[2];
- ULong *L = (ULong *)a, *M = (ULong *)b;
-
- B[0] = Balloc(2);
- B[0]->wds = 4;
- k = strtoIg(s, sp, &fpi, exp, B, rv);
- ULtoQ(L, B[0]->x, exp[0], rv[0]);
- Bfree(B[0]);
- if (B[1]) {
- ULtoQ(M, B[1]->x, exp[1], rv[1]);
- Bfree(B[1]);
- }
- else {
- M[0] = L[0];
- M[1] = L[1];
- M[2] = L[2];
- M[3] = L[3];
- }
- return k;
- }
diff --git a/lib/libc/gdtoa/strtoId.c b/lib/libc/gdtoa/strtoId.c
deleted file mode 100644
index 1c97d382dea..00000000000
--- a/lib/libc/gdtoa/strtoId.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoId(s, sp, f0, f1) CONST char *s; char **sp; double *f0, *f1;
-#else
-strtoId(CONST char *s, char **sp, double *f0, double *f1)
-#endif
-{
- static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
- Long exp[2];
- Bigint *B[2];
- int k, rv[2];
-
- B[0] = Balloc(1);
- B[0]->wds = 2;
- k = strtoIg(s, sp, &fpi, exp, B, rv);
- ULtod((ULong*)f0, B[0]->x, exp[0], rv[0]);
- Bfree(B[0]);
- if (B[1]) {
- ULtod((ULong*)f1, B[1]->x, exp[1], rv[1]);
- Bfree(B[1]);
- }
- else {
- ((ULong*)f1)[0] = ((ULong*)f0)[0];
- ((ULong*)f1)[1] = ((ULong*)f0)[1];
- }
- return k;
- }
diff --git a/lib/libc/gdtoa/strtoIdd.c b/lib/libc/gdtoa/strtoIdd.c
deleted file mode 100644
index 40b7936bc00..00000000000
--- a/lib/libc/gdtoa/strtoIdd.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoIdd(s, sp, f0, f1) CONST char *s; char **sp; double *f0, *f1;
-#else
-strtoIdd(CONST char *s, char **sp, double *f0, double *f1)
-#endif
-{
-#ifdef Sudden_Underflow
- static FPI fpi = { 106, 1-1023, 2046-1023-106+1, 1, 1 };
-#else
- static FPI fpi = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
-#endif
- Long exp[2];
- Bigint *B[2];
- int k, rv[2];
-
- B[0] = Balloc(2);
- B[0]->wds = 4;
- k = strtoIg(s, sp, &fpi, exp, B, rv);
- ULtodd((ULong*)f0, B[0]->x, exp[0], rv[0]);
- Bfree(B[0]);
- if (B[1]) {
- ULtodd((ULong*)f1, B[1]->x, exp[1], rv[1]);
- Bfree(B[1]);
- }
- else {
- ((ULong*)f1)[0] = ((ULong*)f0)[0];
- ((ULong*)f1)[1] = ((ULong*)f0)[1];
- ((ULong*)f1)[2] = ((ULong*)f0)[2];
- ((ULong*)f1)[3] = ((ULong*)f0)[3];
- }
- return k;
- }
diff --git a/lib/libc/gdtoa/strtoIf.c b/lib/libc/gdtoa/strtoIf.c
deleted file mode 100644
index 65ecab2e0b8..00000000000
--- a/lib/libc/gdtoa/strtoIf.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoIf(s, sp, f0, f1) CONST char *s; char **sp; float *f0, *f1;
-#else
-strtoIf(CONST char *s, char **sp, float *f0, float *f1)
-#endif
-{
- static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
- Long exp[2];
- Bigint *B[2];
- int k, rv[2];
-
- B[0] = Balloc(0);
- B[0]->wds = 1;
- k = strtoIg(s, sp, &fpi, exp, B, rv);
- ULtof((ULong*)f0, B[0]->x, exp[0], rv[0]);
- Bfree(B[0]);
- if (B[1]) {
- ULtof((ULong*)f1, B[1]->x, exp[1], rv[1]);
- Bfree(B[1]);
- }
- else
- *(ULong*)f1 = *(ULong*)f0;
- return k;
- }
diff --git a/lib/libc/gdtoa/strtoIg.c b/lib/libc/gdtoa/strtoIg.c
deleted file mode 100644
index 90c88db3283..00000000000
--- a/lib/libc/gdtoa/strtoIg.c
+++ /dev/null
@@ -1,137 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoIg(s00, se, fpi, exp, B, rvp) CONST char *s00; char **se; FPI *fpi; Long *exp; Bigint **B; int *rvp;
-#else
-strtoIg(CONST char *s00, char **se, FPI *fpi, Long *exp, Bigint **B, int *rvp)
-#endif
-{
- Bigint *b, *b1;
- int i, nb, nw, nw1, rv, rv1, swap;
- unsigned int nb1, nb11;
- Long e1;
-
- b = *B;
- rv = strtodg(s00, se, fpi, exp, b->x);
- if (!(rv & STRTOG_Inexact)) {
- B[1] = 0;
- return *rvp = rv;
- }
- e1 = exp[0];
- rv1 = rv ^ STRTOG_Inexact;
- b1 = Balloc(b->k);
- Bcopy(b1, b);
- nb = fpi->nbits;
- nb1 = nb & 31;
- nb11 = (nb1 - 1) & 31;
- nw = b->wds;
- nw1 = nw - 1;
- if (rv & STRTOG_Inexlo) {
- swap = 0;
- b1 = increment(b1);
- if ((rv & STRTOG_Retmask) == STRTOG_Zero) {
- if (fpi->sudden_underflow) {
- b1->x[0] = 0;
- b1->x[nw1] = 1L << nb11;
- rv1 += STRTOG_Normal - STRTOG_Zero;
- rv1 &= ~STRTOG_Underflow;
- goto swapcheck;
- }
- rv1 &= STRTOG_Inexlo | STRTOG_Underflow | STRTOG_Zero;
- rv1 |= STRTOG_Inexhi | STRTOG_Denormal;
- goto swapcheck;
- }
- if (b1->wds > nw
- || nb1 && b1->x[nw1] & 1L << nb1) {
- if (++e1 > fpi->emax)
- rv1 = STRTOG_Infinite | STRTOG_Inexhi;
- rshift(b1, 1);
- }
- else if ((rv & STRTOG_Retmask) == STRTOG_Denormal) {
- if (b1->x[nw1] & 1L << nb11) {
- rv1 += STRTOG_Normal - STRTOG_Denormal;
- rv1 &= ~STRTOG_Underflow;
- }
- }
- }
- else {
- swap = STRTOG_Neg;
- if ((rv & STRTOG_Retmask) == STRTOG_Infinite) {
- b1 = set_ones(b1, nb);
- e1 = fpi->emax;
- rv1 = STRTOG_Normal | STRTOG_Inexlo;
- goto swapcheck;
- }
- decrement(b1);
- if ((rv & STRTOG_Retmask) == STRTOG_Denormal) {
- for(i = nw1; !b1->x[i]; --i)
- if (!i) {
- rv1 = STRTOG_Zero | STRTOG_Inexlo;
- break;
- }
- goto swapcheck;
- }
- if (!(b1->x[nw1] & 1L << nb11)) {
- if (e1 == fpi->emin) {
- if (fpi->sudden_underflow)
- rv1 += STRTOG_Zero - STRTOG_Normal;
- else
- rv1 += STRTOG_Denormal - STRTOG_Normal;
- rv1 |= STRTOG_Underflow;
- }
- else {
- b1 = lshift(b1, 1);
- b1->x[0] |= 1;
- --e1;
- }
- }
- }
- swapcheck:
- if (swap ^ (rv & STRTOG_Neg)) {
- rvp[0] = rv1;
- rvp[1] = rv;
- B[0] = b1;
- B[1] = b;
- exp[1] = exp[0];
- exp[0] = e1;
- }
- else {
- rvp[0] = rv;
- rvp[1] = rv1;
- B[1] = b1;
- exp[1] = e1;
- }
- return rv;
- }
diff --git a/lib/libc/gdtoa/strtoIx.c b/lib/libc/gdtoa/strtoIx.c
deleted file mode 100644
index 783a631f066..00000000000
--- a/lib/libc/gdtoa/strtoIx.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoIx(s, sp, a, b) CONST char *s; char **sp; void *a; void *b;
-#else
-strtoIx(CONST char *s, char **sp, void *a, void *b)
-#endif
-{
- static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
- Long exp[2];
- Bigint *B[2];
- int k, rv[2];
- UShort *L = (UShort *)a, *M = (UShort *)b;
-
- B[0] = Balloc(1);
- B[0]->wds = 2;
- k = strtoIg(s, sp, &fpi, exp, B, rv);
- ULtox(L, B[0]->x, exp[0], rv[0]);
- Bfree(B[0]);
- if (B[1]) {
- ULtox(M, B[1]->x, exp[1], rv[1]);
- Bfree(B[1]);
- }
- else {
- M[0] = L[0];
- M[1] = L[1];
- M[2] = L[2];
- M[3] = L[3];
- M[4] = L[4];
- }
- return k;
- }
diff --git a/lib/libc/gdtoa/strtoIxL.c b/lib/libc/gdtoa/strtoIxL.c
deleted file mode 100644
index 869bfd16fb8..00000000000
--- a/lib/libc/gdtoa/strtoIxL.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtoIxL(s, sp, a, b) CONST char *s; char **sp; void *a; void *b;
-#else
-strtoIxL(CONST char *s, char **sp, void *a, void *b)
-#endif
-{
- static FPI fpi = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
- Long exp[2];
- Bigint *B[2];
- int k, rv[2];
- ULong *L = (ULong *)a, *M = (ULong *)b;
-
- B[0] = Balloc(1);
- B[0]->wds = 2;
- k = strtoIg(s, sp, &fpi, exp, B, rv);
- ULtoxL(L, B[0]->x, exp[0], rv[0]);
- Bfree(B[0]);
- if (B[1]) {
- ULtoxL(M, B[1]->x, exp[1], rv[1]);
- Bfree(B[1]);
- }
- else {
- M[0] = L[0];
- M[1] = L[1];
- M[2] = L[2];
- }
- return k;
- }
diff --git a/lib/libc/gdtoa/strtod.c b/lib/libc/gdtoa/strtod.c
index e6a2c699c43..2d2aa375105 100644
--- a/lib/libc/gdtoa/strtod.c
+++ b/lib/libc/gdtoa/strtod.c
@@ -74,7 +74,7 @@ strtod
double aadj, aadj1, adj, rv, rv0;
Long L;
ULong y, z;
- Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
+ Bigint *bb, *bb1, *bd, *bd0 = NULL, *bs, *delta;
#ifdef SET_INEXACT
int inexact, oldinexact;
#endif
@@ -163,6 +163,8 @@ strtod
sign = 0;
case STRTOG_Zero:
break;
+ case STRTOG_NoMemory:
+ goto ovfl;
default:
if (bb) {
copybits(bits, fpi.nbits, bb);
@@ -331,7 +333,6 @@ strtod
#endif
dval(rv) = tens[k - 9] * dval(rv) + z;
}
- bd0 = 0;
if (nd <= DBL_DIG
#ifndef RND_PRODQUOT
#ifndef Honor_FLT_ROUNDS
@@ -548,12 +549,20 @@ strtod
/* Put digits into bd: true value = bd * 10^e */
bd0 = s2b(s0, nd0, nd, y);
+ if (bd0 == NULL)
+ goto ovfl;
for(;;) {
bd = Balloc(bd0->k);
+ if (bd == NULL)
+ goto ovfl;
Bcopy(bd, bd0);
bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
+ if (bb == NULL)
+ goto ovfl;
bs = i2b(1);
+ if (bs == NULL)
+ goto ovfl;
if (e >= 0) {
bb2 = bb5 = 0;
@@ -610,19 +619,37 @@ strtod
}
if (bb5 > 0) {
bs = pow5mult(bs, bb5);
+ if (bs == NULL)
+ goto ovfl;
bb1 = mult(bs, bb);
+ if (bb1 == NULL)
+ goto ovfl;
Bfree(bb);
bb = bb1;
}
- if (bb2 > 0)
+ if (bb2 > 0) {
bb = lshift(bb, bb2);
- if (bd5 > 0)
+ if (bb == NULL)
+ goto ovfl;
+ }
+ if (bd5 > 0) {
bd = pow5mult(bd, bd5);
- if (bd2 > 0)
+ if (bd == NULL)
+ goto ovfl;
+ }
+ if (bd2 > 0) {
bd = lshift(bd, bd2);
- if (bs2 > 0)
+ if (bd == NULL)
+ goto ovfl;
+ }
+ if (bs2 > 0) {
bs = lshift(bs, bs2);
+ if (bs == NULL)
+ goto ovfl;
+ }
delta = diff(bb, bd);
+ if (delta == NULL)
+ goto ovfl;
dsign = delta->sign;
delta->sign = 0;
i = cmp(delta, bs);
@@ -655,6 +682,8 @@ strtod
#endif
{
delta = lshift(delta,Log2P);
+ if (delta == NULL)
+ goto ovfl;
if (cmp(delta, bs) <= 0)
adj = -0.5;
}
@@ -747,6 +776,8 @@ strtod
break;
}
delta = lshift(delta,Log2P);
+ if (delta == NULL)
+ goto ovfl;
if (cmp(delta, bs) > 0)
goto drop_down;
break;
diff --git a/lib/libc/gdtoa/strtodI.c b/lib/libc/gdtoa/strtodI.c
deleted file mode 100644
index 98f889110e0..00000000000
--- a/lib/libc/gdtoa/strtodI.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- static double
-#ifdef KR_headers
-ulpdown(d) double *d;
-#else
-ulpdown(double *d)
-#endif
-{
- double u;
- ULong *L = (ULong*)d;
-
- u = ulp(*d);
- if (!(L[_1] | L[_0] & 0xfffff)
- && (L[_0] & 0x7ff00000) > 0x00100000)
- u *= 0.5;
- return u;
- }
-
- int
-#ifdef KR_headers
-strtodI(s, sp, dd) CONST char *s; char **sp; double *dd;
-#else
-strtodI(CONST char *s, char **sp, double *dd)
-#endif
-{
- static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
- ULong bits[2], sign;
- Long exp;
- int j, k;
- typedef union {
- double d[2];
- ULong L[4];
- } U;
- U *u;
-
- k = strtodg(s, sp, &fpi, &exp, bits);
- u = (U*)dd;
- sign = k & STRTOG_Neg ? 0x80000000L : 0;
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- u->d[0] = u->d[1] = 0.;
- break;
-
- case STRTOG_Zero:
- u->d[0] = u->d[1] = 0.;
-#ifdef Sudden_Underflow
- if (k & STRTOG_Inexact) {
- if (sign)
- u->L[_0] = 0x80100000L;
- else
- u->L[2+_0] = 0x100000L;
- }
- break;
-#else
- goto contain;
-#endif
-
- case STRTOG_Denormal:
- u->L[_1] = bits[0];
- u->L[_0] = bits[1];
- goto contain;
-
- case STRTOG_Normal:
- u->L[_1] = bits[0];
- u->L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
- contain:
- j = k & STRTOG_Inexact;
- if (sign) {
- u->L[_0] |= sign;
- j = STRTOG_Inexact - j;
- }
- switch(j) {
- case STRTOG_Inexlo:
-#ifdef Sudden_Underflow
- if ((u->L[_0] & 0x7ff00000) < 0x3500000) {
- u->L[2+_0] = u->L[_0] + 0x3500000;
- u->L[2+_1] = u->L[_1];
- u->d[1] += ulp(u->d[1]);
- u->L[2+_0] -= 0x3500000;
- if (!(u->L[2+_0] & 0x7ff00000)) {
- u->L[2+_0] = sign;
- u->L[2+_1] = 0;
- }
- }
- else
-#endif
- u->d[1] = u->d[0] + ulp(u->d[0]);
- break;
- case STRTOG_Inexhi:
- u->d[1] = u->d[0];
-#ifdef Sudden_Underflow
- if ((u->L[_0] & 0x7ff00000) < 0x3500000) {
- u->L[_0] += 0x3500000;
- u->d[0] -= ulpdown(u->d);
- u->L[_0] -= 0x3500000;
- if (!(u->L[_0] & 0x7ff00000)) {
- u->L[_0] = sign;
- u->L[_1] = 0;
- }
- }
- else
-#endif
- u->d[0] -= ulpdown(u->d);
- break;
- default:
- u->d[1] = u->d[0];
- }
- break;
-
- case STRTOG_Infinite:
- u->L[_0] = u->L[2+_0] = sign | 0x7ff00000;
- u->L[_1] = u->L[2+_1] = 0;
- if (k & STRTOG_Inexact) {
- if (sign) {
- u->L[2+_0] = 0xffefffffL;
- u->L[2+_1] = 0xffffffffL;
- }
- else {
- u->L[_0] = 0x7fefffffL;
- u->L[_1] = 0xffffffffL;
- }
- }
- break;
-
- case STRTOG_NaN:
- u->L[0] = u->L[2] = d_QNAN0;
- u->L[1] = u->L[3] = d_QNAN1;
- break;
-
- case STRTOG_NaNbits:
- u->L[_0] = u->L[2+_0] = 0x7ff00000 | sign | bits[1];
- u->L[_1] = u->L[2+_1] = bits[0];
- }
- return k;
- }
diff --git a/lib/libc/gdtoa/strtodg.c b/lib/libc/gdtoa/strtodg.c
index 159d3c91bae..a4a422fd507 100644
--- a/lib/libc/gdtoa/strtodg.c
+++ b/lib/libc/gdtoa/strtodg.c
@@ -80,6 +80,8 @@ increment(Bigint *b)
{
if (b->wds >= b->maxwds) {
b1 = Balloc(b->k+1);
+ if (b1 == NULL)
+ return (NULL);
Bcopy(b1,b);
Bfree(b);
b = b1;
@@ -154,6 +156,8 @@ set_ones(Bigint *b, int n)
if (b->k < k) {
Bfree(b);
b = Balloc(k);
+ if (b == NULL)
+ return (NULL);
}
k = n >> kshift;
if (n &= kmask)
@@ -183,6 +187,10 @@ rvOK
carry = rv = 0;
b = d2b(d, &e, &bdif);
+ if (b == NULL) {
+ *irv = STRTOG_NoMemory;
+ return 1;
+ }
bdif -= nb = fpi->nbits;
e += bdif;
if (bdif <= 0) {
@@ -235,6 +243,10 @@ rvOK
if (carry) {
inex = STRTOG_Inexhi;
b = increment(b);
+ if (b == NULL) {
+ *irv = STRTOG_NoMemory;
+ return 1;
+ }
if ( (j = nb & kmask) !=0)
j = ULbits - j;
if (hi0bits(b->x[b->wds - 1]) != j) {
@@ -245,8 +257,13 @@ rvOK
}
}
}
- else if (bdif < 0)
+ else if (bdif < 0) {
b = lshift(b, -bdif);
+ if (b == NULL) {
+ *irv = STRTOG_NoMemory;
+ return 1;
+ }
+ }
if (e < fpi->emin) {
k = fpi->emin - e;
e = fpi->emin;
@@ -266,6 +283,10 @@ rvOK
*irv = STRTOG_Denormal;
if (carry) {
b = increment(b);
+ if (b == NULL) {
+ *irv = STRTOG_NoMemory;
+ return 1;
+ }
inex = STRTOG_Inexhi | STRTOG_Underflow;
}
else if (lostbits)
@@ -385,6 +406,8 @@ strtodg
case 'x':
case 'X':
irv = gethex(&s, fpi, exp, &rvb, sign);
+ if (irv == STRTOG_NoMemory)
+ return (STRTOG_NoMemory);
if (irv == STRTOG_NoNumber) {
s = s00;
sign = 0;
@@ -550,9 +573,12 @@ strtodg
bd0 = 0;
if (nbits <= P && nd <= DBL_DIG) {
if (!e) {
- if (rvOK(dval(rv), fpi, exp, bits, 1, rd, &irv))
+ if (rvOK(dval(rv), fpi, exp, bits, 1, rd, &irv)) {
+ if (irv == STRTOG_NoMemory)
+ return (STRTOG_NoMemory);
goto ret;
}
+ }
else if (e > 0) {
if (e <= Ten_pmax) {
#ifdef VAX
@@ -560,8 +586,11 @@ strtodg
#else
i = fivesbits[e] + mantbits(dval(rv)) <= P;
/* rv = */ rounded_product(dval(rv), tens[e]);
- if (rvOK(dval(rv), fpi, exp, bits, i, rd, &irv))
+ if (rvOK(dval(rv), fpi, exp, bits, i, rd, &irv)) {
+ if (irv == STRTOG_NoMemory)
+ return (STRTOG_NoMemory);
goto ret;
+ }
e1 -= e;
goto rv_notOK;
#endif
@@ -590,16 +619,22 @@ strtodg
#else
/* rv = */ rounded_product(dval(rv), tens[e2]);
#endif
- if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv))
+ if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv)) {
+ if (irv == STRTOG_NoMemory)
+ return (STRTOG_NoMemory);
goto ret;
+ }
e1 -= e2;
}
}
#ifndef Inaccurate_Divide
else if (e >= -Ten_pmax) {
/* rv = */ rounded_quotient(dval(rv), tens[-e]);
- if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv))
+ if (rvOK(dval(rv), fpi, exp, bits, 0, rd, &irv)) {
+ if (irv == STRTOG_NoMemory)
+ return (STRTOG_NoMemory);
goto ret;
+ }
e1 -= e;
}
#endif
@@ -662,6 +697,8 @@ strtodg
e2 <<= 2;
#endif
rvb = d2b(dval(rv), &rve, &rvbits); /* rv = rvb * 2^rve */
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
rve += e2;
if ((j = rvbits - nbits) > 0) {
rshift(rvb, j);
@@ -678,6 +715,8 @@ strtodg
j = rve - emin;
if (j > 0) {
rvb = lshift(rvb, j);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
rvbits += j;
}
else if (j < 0) {
@@ -706,15 +745,23 @@ strtodg
/* Put digits into bd: true value = bd * 10^e */
bd0 = s2b(s0, nd0, nd, y);
+ if (bd0 == NULL)
+ return (STRTOG_NoMemory);
for(;;) {
bd = Balloc(bd0->k);
+ if (bd == NULL)
+ return (STRTOG_NoMemory);
Bcopy(bd, bd0);
bb = Balloc(rvb->k);
+ if (bb == NULL)
+ return (STRTOG_NoMemory);
Bcopy(bb, rvb);
bbbits = rvbits - bb0;
bbe = rve + bb0;
bs = i2b(1);
+ if (bs == NULL)
+ return (STRTOG_NoMemory);
if (e >= 0) {
bb2 = bb5 = 0;
@@ -745,24 +792,42 @@ strtodg
}
if (bb5 > 0) {
bs = pow5mult(bs, bb5);
+ if (bs == NULL)
+ return (STRTOG_NoMemory);
bb1 = mult(bs, bb);
+ if (bb1 == NULL)
+ return (STRTOG_NoMemory);
Bfree(bb);
bb = bb1;
}
bb2 -= bb0;
- if (bb2 > 0)
+ if (bb2 > 0) {
bb = lshift(bb, bb2);
+ if (bb == NULL)
+ return (STRTOG_NoMemory);
+ }
else if (bb2 < 0)
rshift(bb, -bb2);
- if (bd5 > 0)
+ if (bd5 > 0) {
bd = pow5mult(bd, bd5);
- if (bd2 > 0)
+ if (bd == NULL)
+ return (STRTOG_NoMemory);
+ }
+ if (bd2 > 0) {
bd = lshift(bd, bd2);
- if (bs2 > 0)
+ if (bd == NULL)
+ return (STRTOG_NoMemory);
+ }
+ if (bs2 > 0) {
bs = lshift(bs, bs2);
+ if (bs == NULL)
+ return (STRTOG_NoMemory);
+ }
asub = 1;
inex = STRTOG_Inexhi;
delta = diff(bb, bd);
+ if (delta == NULL)
+ return (STRTOG_NoMemory);
if (delta->wds <= 1 && !delta->x[0])
break;
dsign = delta->sign;
@@ -788,6 +853,8 @@ strtodg
goto adj1;
rve = rve1 - 1;
rvb = set_ones(rvb, rvbits = nbits);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
break;
}
irv |= dsign ? STRTOG_Inexlo : STRTOG_Inexhi;
@@ -803,6 +870,8 @@ strtodg
if (dsign || bbbits > 1 || denorm || rve1 == emin)
break;
delta = lshift(delta,1);
+ if (delta == NULL)
+ return (STRTOG_NoMemory);
if (cmp(delta, bs) > 0) {
irv = STRTOG_Normal | STRTOG_Inexlo;
goto drop_down;
@@ -835,6 +904,8 @@ strtodg
}
rve -= nbits;
rvb = set_ones(rvb, rvbits = nbits);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
break;
}
else
@@ -843,6 +914,8 @@ strtodg
break;
if (dsign) {
rvb = increment(rvb);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
j = kmask & (ULbits - (rvbits & kmask));
if (hi0bits(rvb->x[rvb->wds - 1]) != j)
rvbits++;
@@ -907,19 +980,28 @@ strtodg
if (!denorm && rvbits < nbits) {
rvb = lshift(rvb, j = nbits - rvbits);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
rve -= j;
rvbits = nbits;
}
ab = d2b(dval(adj), &abe, &abits);
+ if (ab == NULL)
+ return (STRTOG_NoMemory);
if (abe < 0)
rshift(ab, -abe);
- else if (abe > 0)
+ else if (abe > 0) {
ab = lshift(ab, abe);
+ if (ab == NULL)
+ return (STRTOG_NoMemory);
+ }
rvb0 = rvb;
if (asub) {
/* rv -= adj; */
j = hi0bits(rvb->x[rvb->wds-1]);
rvb = diff(rvb, ab);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
k = rvb0->wds - 1;
if (denorm)
/* do nothing */;
@@ -933,6 +1015,8 @@ strtodg
}
else {
rvb = lshift(rvb, 1);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
--rve;
--rve1;
L = finished = 0;
@@ -941,6 +1025,8 @@ strtodg
}
else {
rvb = sum(rvb, ab);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
k = rvb->wds - 1;
if (k >= rvb0->wds
|| hi0bits(rvb->x[k]) < hi0bits(rvb0->x[k])) {
@@ -984,8 +1070,11 @@ strtodg
Bfree(delta);
}
if (!denorm && (j = nbits - rvbits)) {
- if (j > 0)
+ if (j > 0) {
rvb = lshift(rvb, j);
+ if (rvb == NULL)
+ return (STRTOG_NoMemory);
+ }
else
rshift(rvb, -j);
rve -= j;
diff --git a/lib/libc/gdtoa/strtodnrp.c b/lib/libc/gdtoa/strtodnrp.c
deleted file mode 100644
index 19a769f0b43..00000000000
--- a/lib/libc/gdtoa/strtodnrp.c
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 2004 by David M. Gay.
-All Rights Reserved
-Based on material in the rest of /netlib/fp/gdota.tar.gz,
-which is copyright (C) 1998, 2000 by Lucent Technologies.
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* This is a variant of strtod that works on Intel ia32 systems */
-/* with the default extended-precision arithmetic -- it does not */
-/* require setting the precision control to 53 bits. */
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- double
-#ifdef KR_headers
-strtod(s, sp) CONST char *s; char **sp;
-#else
-strtod(CONST char *s, char **sp)
-#endif
-{
- static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
- ULong bits[2];
- Long exp;
- int k;
- union { ULong L[2]; double d; } u;
-
- k = strtodg(s, sp, &fpi, &exp, bits);
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- u.L[0] = u.L[1] = 0;
- break;
-
- case STRTOG_Normal:
- u.L[_1] = bits[0];
- u.L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
- break;
-
- case STRTOG_Denormal:
- u.L[_1] = bits[0];
- u.L[_0] = bits[1];
- break;
-
- case STRTOG_Infinite:
- u.L[_0] = 0x7ff00000;
- u.L[_1] = 0;
- break;
-
- case STRTOG_NaN:
- u.L[0] = d_QNAN0;
- u.L[1] = d_QNAN1;
- break;
-
- case STRTOG_NaNbits:
- u.L[_0] = 0x7ff00000 | bits[1];
- u.L[_1] = bits[0];
- }
- if (k & STRTOG_Neg)
- u.L[_0] |= 0x80000000L;
- return u.d;
- }
diff --git a/lib/libc/gdtoa/strtof.c b/lib/libc/gdtoa/strtof.c
index f8111b716c2..691dbac4ee9 100644
--- a/lib/libc/gdtoa/strtof.c
+++ b/lib/libc/gdtoa/strtof.c
@@ -65,6 +65,9 @@ strtof(CONST char *s, char **sp)
u.L[0] = bits[0];
break;
+ case STRTOG_NoMemory:
+ errno = ERANGE;
+ /* FALLTHROUGH */
case STRTOG_Infinite:
u.L[0] = 0x7f800000;
break;
diff --git a/lib/libc/gdtoa/strtopQ.c b/lib/libc/gdtoa/strtopQ.c
deleted file mode 100644
index 77f31903374..00000000000
--- a/lib/libc/gdtoa/strtopQ.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#define _3 3
-#endif
-#ifdef IEEE_8087
-#define _0 3
-#define _1 2
-#define _2 1
-#define _3 0
-#endif
-
- int
-#ifdef KR_headers
-strtopQ(s, sp, V) CONST char *s; char **sp; void *V;
-#else
-strtopQ(CONST char *s, char **sp, void *V)
-#endif
-{
- static FPI fpi0 = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, SI };
- ULong bits[4];
- Long exp;
- int k;
- ULong *L = (ULong*)V;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- k = strtodg(s, sp, fpi, &exp, bits);
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- L[0] = L[1] = L[2] = L[3] = 0;
- break;
-
- case STRTOG_Normal:
- case STRTOG_NaNbits:
- L[_3] = bits[0];
- L[_2] = bits[1];
- L[_1] = bits[2];
- L[_0] = (bits[3] & ~0x10000) | ((exp + 0x3fff + 112) << 16);
- break;
-
- case STRTOG_Denormal:
- L[_3] = bits[0];
- L[_2] = bits[1];
- L[_1] = bits[2];
- L[_0] = bits[3];
- break;
-
- case STRTOG_Infinite:
- L[_0] = 0x7fff0000;
- L[_1] = L[_2] = L[_3] = 0;
- break;
-
- case STRTOG_NaN:
- L[0] = ld_QNAN0;
- L[1] = ld_QNAN1;
- L[2] = ld_QNAN2;
- L[3] = ld_QNAN3;
- }
- if (k & STRTOG_Neg)
- L[_0] |= 0x80000000L;
- return k;
- }
diff --git a/lib/libc/gdtoa/strtopd.c b/lib/libc/gdtoa/strtopd.c
deleted file mode 100644
index 0fb35daeaa5..00000000000
--- a/lib/libc/gdtoa/strtopd.c
+++ /dev/null
@@ -1,54 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtopd(s, sp, d) char *s; char **sp; double *d;
-#else
-strtopd(CONST char *s, char **sp, double *d)
-#endif
-{
- static FPI fpi0 = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
- ULong bits[2];
- Long exp;
- int k;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- k = strtodg(s, sp, fpi, &exp, bits);
- ULtod((ULong*)d, bits, exp, k);
- return k;
- }
diff --git a/lib/libc/gdtoa/strtopdd.c b/lib/libc/gdtoa/strtopdd.c
deleted file mode 100644
index c6659761abb..00000000000
--- a/lib/libc/gdtoa/strtopdd.c
+++ /dev/null
@@ -1,183 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtopdd(s, sp, dd) CONST char *s; char **sp; double *dd;
-#else
-strtopdd(CONST char *s, char **sp, double *dd)
-#endif
-{
-#ifdef Sudden_Underflow
- static FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 };
-#else
- static FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
-#endif
- ULong bits[4];
- Long exp;
- int i, j, rv;
- typedef union {
- double d[2];
- ULong L[4];
- } U;
- U *u;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- rv = strtodg(s, sp, fpi, &exp, bits);
- u = (U*)dd;
- switch(rv & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- u->d[0] = u->d[1] = 0.;
- break;
-
- case STRTOG_Normal:
- u->L[_1] = (bits[1] >> 21 | bits[2] << 11) & 0xffffffffL;
- u->L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff
- | exp + 0x3ff + 105 << 20;
- exp += 0x3ff + 52;
- if (bits[1] &= 0x1fffff) {
- i = hi0bits(bits[1]) - 11;
- if (i >= exp) {
- i = exp - 1;
- exp = 0;
- }
- else
- exp -= i;
- if (i > 0) {
- bits[1] = bits[1] << i | bits[0] >> 32-i;
- bits[0] = bits[0] << i & 0xffffffffL;
- }
- }
- else if (bits[0]) {
- i = hi0bits(bits[0]) + 21;
- if (i >= exp) {
- i = exp - 1;
- exp = 0;
- }
- else
- exp -= i;
- if (i < 32) {
- bits[1] = bits[0] >> 32 - i;
- bits[0] = bits[0] << i & 0xffffffffL;
- }
- else {
- bits[1] = bits[0] << i - 32;
- bits[0] = 0;
- }
- }
- else {
- u->L[2] = u->L[3] = 0;
- break;
- }
- u->L[2+_1] = bits[0];
- u->L[2+_0] = bits[1] & 0xfffff | exp << 20;
- break;
-
- case STRTOG_Denormal:
- if (bits[3])
- goto nearly_normal;
- if (bits[2])
- goto partly_normal;
- if (bits[1] & 0xffe00000)
- goto hardly_normal;
- /* completely denormal */
- u->L[2] = u->L[3] = 0;
- u->L[_1] = bits[0];
- u->L[_0] = bits[1];
- break;
-
- nearly_normal:
- i = hi0bits(bits[3]) - 11; /* i >= 12 */
- j = 32 - i;
- u->L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff
- | 65 - i << 20;
- u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
- u->L[2+_0] = bits[1] & (1L << j) - 1;
- u->L[2+_1] = bits[0];
- break;
-
- partly_normal:
- i = hi0bits(bits[2]) - 11;
- if (i < 0) {
- j = -i;
- i += 32;
- u->L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20;
- u->L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
- u->L[2+_0] = bits[1] & (1L << j) - 1;
- u->L[2+_1] = bits[0];
- break;
- }
- if (i == 0) {
- u->L[_0] = bits[2] & 0xfffff | 33 << 20;
- u->L[_1] = bits[1];
- u->L[2+_0] = 0;
- u->L[2+_1] = bits[0];
- break;
- }
- j = 32 - i;
- u->L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff
- | j + 1 << 20;
- u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
- u->L[2+_0] = 0;
- u->L[2+_1] = bits[0] & (1L << j) - 1;
- break;
-
- hardly_normal:
- j = 11 - hi0bits(bits[1]);
- i = 32 - j;
- u->L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20;
- u->L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
- u->L[2+_0] = 0;
- u->L[2+_1] = bits[0] & (1L << j) - 1;
- break;
-
- case STRTOG_Infinite:
- u->L[_0] = u->L[2+_0] = 0x7ff00000;
- u->L[_1] = u->L[2+_1] = 0;
- break;
-
- case STRTOG_NaN:
- u->L[0] = u->L[2] = d_QNAN0;
- u->L[1] = u->L[3] = d_QNAN1;
- }
- if (rv & STRTOG_Neg) {
- u->L[ _0] |= 0x80000000L;
- u->L[2+_0] |= 0x80000000L;
- }
- return rv;
- }
diff --git a/lib/libc/gdtoa/strtopf.c b/lib/libc/gdtoa/strtopf.c
deleted file mode 100644
index 74694a07ef5..00000000000
--- a/lib/libc/gdtoa/strtopf.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- int
-#ifdef KR_headers
-strtopf(s, sp, f) CONST char *s; char **sp; float *f;
-#else
-strtopf(CONST char *s, char **sp, float *f)
-#endif
-{
- static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
- ULong bits[1], *L;
- Long exp;
- int k;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- k = strtodg(s, sp, fpi, &exp, bits);
- L = (ULong*)f;
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- L[0] = 0;
- break;
-
- case STRTOG_Normal:
- case STRTOG_NaNbits:
- L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23;
- break;
-
- case STRTOG_Denormal:
- L[0] = bits[0];
- break;
-
- case STRTOG_Infinite:
- L[0] = 0x7f800000;
- break;
-
- case STRTOG_NaN:
- L[0] = f_QNAN;
- }
- if (k & STRTOG_Neg)
- L[0] |= 0x80000000L;
- return k;
- }
diff --git a/lib/libc/gdtoa/strtopx.c b/lib/libc/gdtoa/strtopx.c
deleted file mode 100644
index 07d04587b00..00000000000
--- a/lib/libc/gdtoa/strtopx.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#define _3 3
-#define _4 4
-#endif
-#ifdef IEEE_8087
-#define _0 4
-#define _1 3
-#define _2 2
-#define _3 1
-#define _4 0
-#endif
-
- int
-#ifdef KR_headers
-strtopx(s, sp, V) CONST char *s; char **sp; void *V;
-#else
-strtopx(CONST char *s, char **sp, void *V)
-#endif
-{
- static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
- ULong bits[2];
- Long exp;
- int k;
- UShort *L = (UShort*)V;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- k = strtodg(s, sp, fpi, &exp, bits);
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- L[0] = L[1] = L[2] = L[3] = L[4] = 0;
- break;
-
- case STRTOG_Denormal:
- L[_0] = 0;
- goto normal_bits;
-
- case STRTOG_Normal:
- case STRTOG_NaNbits:
- L[_0] = exp + 0x3fff + 63;
- normal_bits:
- L[_4] = (UShort)bits[0];
- L[_3] = (UShort)(bits[0] >> 16);
- L[_2] = (UShort)bits[1];
- L[_1] = (UShort)(bits[1] >> 16);
- break;
-
- case STRTOG_Infinite:
- L[_0] = 0x7fff;
- L[_1] = L[_2] = L[_3] = L[_4] = 0;
- break;
-
- case STRTOG_NaN:
- L[0] = ldus_QNAN0;
- L[1] = ldus_QNAN1;
- L[2] = ldus_QNAN2;
- L[3] = ldus_QNAN3;
- L[4] = ldus_QNAN4;
- }
- if (k & STRTOG_Neg)
- L[_0] |= 0x8000;
- return k;
- }
diff --git a/lib/libc/gdtoa/strtopxL.c b/lib/libc/gdtoa/strtopxL.c
deleted file mode 100644
index b0f5cdd0d81..00000000000
--- a/lib/libc/gdtoa/strtopxL.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#endif
-#ifdef IEEE_8087
-#define _0 2
-#define _1 1
-#define _2 0
-#endif
-
- int
-#ifdef KR_headers
-strtopxL(s, sp, V) CONST char *s; char **sp; void *V;
-#else
-strtopxL(CONST char *s, char **sp, void *V)
-#endif
-{
- static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
- ULong bits[2];
- Long exp;
- int k;
- ULong *L = (ULong*)V;
-#ifdef Honor_FLT_ROUNDS
-#include "gdtoa_fltrnds.h"
-#else
-#define fpi &fpi0
-#endif
-
- k = strtodg(s, sp, fpi, &exp, bits);
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- L[0] = L[1] = L[2] = 0;
- break;
-
- case STRTOG_Normal:
- case STRTOG_Denormal:
- case STRTOG_NaNbits:
- L[_2] = bits[0];
- L[_1] = bits[1];
- L[_0] = (exp + 0x3fff + 63) << 16;
- break;
-
- case STRTOG_Infinite:
- L[_0] = 0x7fff << 16;
- L[_1] = L[_2] = 0;
- break;
-
- case STRTOG_NaN:
- L[0] = ld_QNAN0;
- L[1] = ld_QNAN1;
- L[2] = ld_QNAN2;
- }
- if (k & STRTOG_Neg)
- L[_0] |= 0x80000000L;
- return k;
- }
diff --git a/lib/libc/gdtoa/strtorQ.c b/lib/libc/gdtoa/strtorQ.c
index a9a07da04ea..715cb089afc 100644
--- a/lib/libc/gdtoa/strtorQ.c
+++ b/lib/libc/gdtoa/strtorQ.c
@@ -77,6 +77,9 @@ ULtoQ(ULong *L, ULong *bits, Long exp, int k)
L[_0] = bits[3];
break;
+ case STRTOG_NoMemory:
+ errno = ERANGE;
+ /* FALLTHROUGH */
case STRTOG_Infinite:
L[_0] = 0x7fff0000;
L[_1] = L[_2] = L[_3] = 0;
diff --git a/lib/libc/gdtoa/strtord.c b/lib/libc/gdtoa/strtord.c
index 709af4c713f..966d26431b4 100644
--- a/lib/libc/gdtoa/strtord.c
+++ b/lib/libc/gdtoa/strtord.c
@@ -55,6 +55,9 @@ ULtod(ULong *L, ULong *bits, Long exp, int k)
L[_0] = (bits[1] & ~0x100000) | ((exp + 0x3ff + 52) << 20);
break;
+ case STRTOG_NoMemory:
+ errno = ERANGE;
+ /* FALLTHROUGH */
case STRTOG_Infinite:
L[_0] = 0x7ff00000;
L[_1] = 0;
diff --git a/lib/libc/gdtoa/strtordd.c b/lib/libc/gdtoa/strtordd.c
deleted file mode 100644
index 9c2b46e65e3..00000000000
--- a/lib/libc/gdtoa/strtordd.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- void
-#ifdef KR_headers
-ULtodd(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
-#else
-ULtodd(ULong *L, ULong *bits, Long exp, int k)
-#endif
-{
- int i, j;
-
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- L[0] = L[1] = L[2] = L[3] = 0;
- break;
-
- case STRTOG_Normal:
- L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL;
- L[_0] = bits[2] >> 21 | bits[3] << 11 & 0xfffff
- | exp + 0x3ff + 105 << 20;
- exp += 0x3ff + 52;
- if (bits[1] &= 0x1fffff) {
- i = hi0bits(bits[1]) - 11;
- if (i >= exp) {
- i = exp - 1;
- exp = 0;
- }
- else
- exp -= i;
- if (i > 0) {
- bits[1] = bits[1] << i | bits[0] >> 32-i;
- bits[0] = bits[0] << i & (ULong)0xffffffffL;
- }
- }
- else if (bits[0]) {
- i = hi0bits(bits[0]) + 21;
- if (i >= exp) {
- i = exp - 1;
- exp = 0;
- }
- else
- exp -= i;
- if (i < 32) {
- bits[1] = bits[0] >> 32 - i;
- bits[0] = bits[0] << i & (ULong)0xffffffffL;
- }
- else {
- bits[1] = bits[0] << i - 32;
- bits[0] = 0;
- }
- }
- else {
- L[2] = L[3] = 0;
- break;
- }
- L[2+_1] = bits[0];
- L[2+_0] = bits[1] & 0xfffff | exp << 20;
- break;
-
- case STRTOG_Denormal:
- if (bits[3])
- goto nearly_normal;
- if (bits[2])
- goto partly_normal;
- if (bits[1] & 0xffe00000)
- goto hardly_normal;
- /* completely denormal */
- L[2] = L[3] = 0;
- L[_1] = bits[0];
- L[_0] = bits[1];
- break;
-
- nearly_normal:
- i = hi0bits(bits[3]) - 11; /* i >= 12 */
- j = 32 - i;
- L[_0] = (bits[3] << i | bits[2] >> j) & 0xfffff
- | 65 - i << 20;
- L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
- L[2+_0] = bits[1] & ((ULong)1L << j) - 1;
- L[2+_1] = bits[0];
- break;
-
- partly_normal:
- i = hi0bits(bits[2]) - 11;
- if (i < 0) {
- j = -i;
- i += 32;
- L[_0] = bits[2] >> j & 0xfffff | (33 + j) << 20;
- L[_1] = (bits[2] << i | bits[1] >> j) & 0xffffffffL;
- L[2+_0] = bits[1] & ((ULong)1L << j) - 1;
- L[2+_1] = bits[0];
- break;
- }
- if (i == 0) {
- L[_0] = bits[2] & 0xfffff | 33 << 20;
- L[_1] = bits[1];
- L[2+_0] = 0;
- L[2+_1] = bits[0];
- break;
- }
- j = 32 - i;
- L[_0] = (bits[2] << i | bits[1] >> j) & 0xfffff
- | j + 1 << 20;
- L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
- L[2+_0] = 0;
- L[2+_1] = bits[0] & (1L << j) - 1;
- break;
-
- hardly_normal:
- j = 11 - hi0bits(bits[1]);
- i = 32 - j;
- L[_0] = bits[1] >> j & 0xfffff | j + 1 << 20;
- L[_1] = (bits[1] << i | bits[0] >> j) & 0xffffffffL;
- L[2+_0] = 0;
- L[2+_1] = bits[0] & ((ULong)1L << j) - 1;
- break;
-
- case STRTOG_Infinite:
- L[_0] = L[2+_0] = 0x7ff00000;
- L[_1] = L[2+_1] = 0;
- break;
-
- case STRTOG_NaN:
- L[0] = L[2] = d_QNAN0;
- L[1] = L[3] = d_QNAN1;
- break;
-
- case STRTOG_NaNbits:
- L[_1] = (bits[1] >> 21 | bits[2] << 11) & (ULong)0xffffffffL;
- L[_0] = bits[2] >> 21 | bits[3] << 11
- | (ULong)0x7ff00000L;
- L[2+_1] = bits[0];
- L[2+_0] = bits[1] | (ULong)0x7ff00000L;
- }
- if (k & STRTOG_Neg) {
- L[_0] |= 0x80000000L;
- L[2+_0] |= 0x80000000L;
- }
- }
-
- int
-#ifdef KR_headers
-strtordd(s, sp, rounding, dd) CONST char *s; char **sp; int rounding; double *dd;
-#else
-strtordd(CONST char *s, char **sp, int rounding, double *dd)
-#endif
-{
-#ifdef Sudden_Underflow
- static FPI fpi0 = { 106, 1-1023, 2046-1023-106+1, 1, 1 };
-#else
- static FPI fpi0 = { 106, 1-1023-53+1, 2046-1023-106+1, 1, 0 };
-#endif
- FPI *fpi, fpi1;
- ULong bits[4];
- Long exp;
- int k;
-
- fpi = &fpi0;
- if (rounding != FPI_Round_near) {
- fpi1 = fpi0;
- fpi1.rounding = rounding;
- fpi = &fpi1;
- }
- k = strtodg(s, sp, fpi, &exp, bits);
- ULtodd((ULong*)dd, bits, exp, k);
- return k;
- }
diff --git a/lib/libc/gdtoa/strtorf.c b/lib/libc/gdtoa/strtorf.c
deleted file mode 100644
index 46b0ba2e424..00000000000
--- a/lib/libc/gdtoa/strtorf.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
- void
-#ifdef KR_headers
-ULtof(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
-#else
-ULtof(ULong *L, ULong *bits, Long exp, int k)
-#endif
-{
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- *L = 0;
- break;
-
- case STRTOG_Normal:
- case STRTOG_NaNbits:
- L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23;
- break;
-
- case STRTOG_Denormal:
- L[0] = bits[0];
- break;
-
- case STRTOG_Infinite:
- L[0] = 0x7f800000;
- break;
-
- case STRTOG_NaN:
- L[0] = f_QNAN;
- }
- if (k & STRTOG_Neg)
- L[0] |= 0x80000000L;
- }
-
- int
-#ifdef KR_headers
-strtorf(s, sp, rounding, f) CONST char *s; char **sp; int rounding; float *f;
-#else
-strtorf(CONST char *s, char **sp, int rounding, float *f)
-#endif
-{
- static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI };
- FPI *fpi, fpi1;
- ULong bits[1];
- Long exp;
- int k;
-
- fpi = &fpi0;
- if (rounding != FPI_Round_near) {
- fpi1 = fpi0;
- fpi1.rounding = rounding;
- fpi = &fpi1;
- }
- k = strtodg(s, sp, fpi, &exp, bits);
- ULtof((ULong*)f, bits, exp, k);
- return k;
- }
diff --git a/lib/libc/gdtoa/strtorx.c b/lib/libc/gdtoa/strtorx.c
index 23f721aa293..201d7149121 100644
--- a/lib/libc/gdtoa/strtorx.c
+++ b/lib/libc/gdtoa/strtorx.c
@@ -78,6 +78,9 @@ ULtox(UShort *L, ULong *bits, Long exp, int k)
L[_1] = (UShort)(bits[1] >> 16);
break;
+ case STRTOG_NoMemory:
+ errno = ERANGE;
+ /* FALLTHROUGH */
case STRTOG_Infinite:
L[_0] = 0x7fff;
L[_1] = L[_2] = L[_3] = L[_4] = 0;
diff --git a/lib/libc/gdtoa/strtorxL.c b/lib/libc/gdtoa/strtorxL.c
deleted file mode 100644
index ff62a61302a..00000000000
--- a/lib/libc/gdtoa/strtorxL.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/****************************************************************
-
-The author of this software is David M. Gay.
-
-Copyright (C) 1998, 2000 by Lucent Technologies
-All Rights Reserved
-
-Permission to use, copy, modify, and distribute this software and
-its documentation for any purpose and without fee is hereby
-granted, provided that the above copyright notice appear in all
-copies and that both that the copyright notice and this
-permission notice and warranty disclaimer appear in supporting
-documentation, and that the name of Lucent or any of its entities
-not be used in advertising or publicity pertaining to
-distribution of the software without specific, written prior
-permission.
-
-LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
-INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
-IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
-SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
-IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
-ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
-THIS SOFTWARE.
-
-****************************************************************/
-
-/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
-
-#include "gdtoaimp.h"
-
-#undef _0
-#undef _1
-
-/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */
-
-#ifdef IEEE_MC68k
-#define _0 0
-#define _1 1
-#define _2 2
-#endif
-#ifdef IEEE_8087
-#define _0 2
-#define _1 1
-#define _2 0
-#endif
-
- void
-#ifdef KR_headers
-ULtoxL(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k;
-#else
-ULtoxL(ULong *L, ULong *bits, Long exp, int k)
-#endif
-{
- switch(k & STRTOG_Retmask) {
- case STRTOG_NoNumber:
- case STRTOG_Zero:
- L[0] = L[1] = L[2] = 0;
- break;
-
- case STRTOG_Normal:
- case STRTOG_Denormal:
- case STRTOG_NaNbits:
- L[_0] = (exp + 0x3fff + 63) << 16;
- L[_1] = bits[1];
- L[_2] = bits[0];
- break;
-
- case STRTOG_Infinite:
- L[_0] = 0x7fff << 16;
- L[_1] = L[_2] = 0;
- break;
-
- case STRTOG_NaN:
- L[0] = ld_QNAN0;
- L[1] = ld_QNAN1;
- L[2] = ld_QNAN2;
- }
- if (k & STRTOG_Neg)
- L[_0] |= 0x80000000L;
- }
-
- int
-#ifdef KR_headers
-strtorxL(s, sp, rounding, L) CONST char *s; char **sp; int rounding; void *L;
-#else
-strtorxL(CONST char *s, char **sp, int rounding, void *L)
-#endif
-{
- static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
- FPI *fpi, fpi1;
- ULong bits[2];
- Long exp;
- int k;
-
- fpi = &fpi0;
- if (rounding != FPI_Round_near) {
- fpi1 = fpi0;
- fpi1.rounding = rounding;
- fpi = &fpi1;
- }
- k = strtodg(s, sp, fpi, &exp, bits);
- ULtoxL((ULong*)L, bits, exp, k);
- return k;
- }
diff --git a/lib/libc/gdtoa/sum.c b/lib/libc/gdtoa/sum.c
index dc0c88bcfab..c6eb954f044 100644
--- a/lib/libc/gdtoa/sum.c
+++ b/lib/libc/gdtoa/sum.c
@@ -48,6 +48,8 @@ sum(Bigint *a, Bigint *b)
c = b; b = a; a = c;
}
c = Balloc(a->k);
+ if (c == NULL)
+ return (NULL);
c->wds = a->wds;
carry = 0;
xa = a->x;
@@ -88,6 +90,8 @@ sum(Bigint *a, Bigint *b)
if (carry) {
if (c->wds == c->maxwds) {
b = Balloc(c->k + 1);
+ if (b == NULL)
+ return (NULL);
Bcopy(b, c);
Bfree(c);
c = b;
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 466d5384a5f..7d7958b69df 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfprintf.c,v 1.53 2008/10/21 17:51:17 martynas Exp $ */
+/* $OpenBSD: vfprintf.c,v 1.54 2009/10/16 12:15:03 martynas Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -576,11 +576,19 @@ reswitch: switch (ch) {
dtoaresult = cp =
__hldtoa(fparg.ldbl, xdigs, prec,
&expt, &signflag, &dtoaend);
+ if (dtoaresult == NULL) {
+ errno = ENOMEM;
+ goto error;
+ }
} else {
fparg.dbl = GETARG(double);
dtoaresult = cp =
__hdtoa(fparg.dbl, xdigs, prec,
&expt, &signflag, &dtoaend);
+ if (dtoaresult == NULL) {
+ errno = ENOMEM;
+ goto error;
+ }
}
if (prec < 0)
prec = dtoaend - cp;
@@ -614,11 +622,19 @@ fp_begin:
dtoaresult = cp =
__ldtoa(&fparg.ldbl, expchar ? 2 : 3, prec,
&expt, &signflag, &dtoaend);
+ if (dtoaresult == NULL) {
+ errno = ENOMEM;
+ goto error;
+ }
} else {
fparg.dbl = GETARG(double);
dtoaresult = cp =
__dtoa(fparg.dbl, expchar ? 2 : 3, prec,
&expt, &signflag, &dtoaend);
+ if (dtoaresult == NULL) {
+ errno = ENOMEM;
+ goto error;
+ }
if (expt == 9999)
expt = INT_MAX;
}
diff --git a/lib/libc/stdlib/ecvt.c b/lib/libc/stdlib/ecvt.c
index 719370a8f37..03ff9189677 100644
--- a/lib/libc/stdlib/ecvt.c
+++ b/lib/libc/stdlib/ecvt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ecvt.c,v 1.6 2006/10/29 18:45:56 deraadt Exp $ */
+/* $OpenBSD: ecvt.c,v 1.7 2009/10/16 12:15:03 martynas Exp $ */
/*
* Copyright (c) 2002, 2006 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -62,6 +62,8 @@ __cvt(double value, int ndigit, int *decpt, int *sign, int fmode, int pad)
*rve = '\0';
} else {
p = __dtoa(value, fmode + 2, ndigit, decpt, sign, &rve);
+ if (p == NULL)
+ return (NULL);
if (*decpt == 9999) {
/* Infinity or Nan, convert to inf or nan like printf */
*decpt = 0;
diff --git a/lib/libc/stdlib/gcvt.c b/lib/libc/stdlib/gcvt.c
index c24157e465a..e5488d912dd 100644
--- a/lib/libc/stdlib/gcvt.c
+++ b/lib/libc/stdlib/gcvt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gcvt.c,v 1.10 2006/10/29 18:45:56 deraadt Exp $ */
+/* $OpenBSD: gcvt.c,v 1.11 2009/10/16 12:15:03 martynas Exp $ */
/*
* Copyright (c) 2002, 2003, 2006 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -42,6 +42,8 @@ gcvt(double value, int ndigit, char *buf)
}
digits = __dtoa(value, 2, ndigit, &decpt, &sign, NULL);
+ if (digits == NULL)
+ return (NULL);
if (decpt == 9999) {
/*
* Infinity or NaN, convert to inf or nan with sign.