[4448] in Athena Bugs
libc: gcvt(), ecvt()
daemon@ATHENA.MIT.EDU (John Carr)
Wed Mar 7 22:25:31 1990
To: bugs@ATHENA.MIT.EDU
Date: Wed, 07 Mar 90 22:25:09 EST
From: John Carr <jfc@ATHENA.MIT.EDU>
The following patches fix changes.70 #260.
There is a bug in gcvt() when using IEEE floating point: it assumes
that exponents have absolute value < 100. Also, both gcvt() and
ecvt() can potentially overrun strings.
gcvt() is common code, ecvt is RT (or at least, IEEE math) specific.
*** /source/bsd-4.3/common/lib/libc/gen/gcvt.c Sun Mar 9 22:46:56 1986
--- gcvt.c Wed Mar 7 22:18:20 1990
***************
*** 8,13 ****
--- 8,14 ----
*/
char *ecvt();
+ int strlen();
char *
gcvt(number, ndigit, buf)
***************
*** 14,20 ****
double number;
char *buf;
{
! int sign, decpt;
register char *p1, *p2;
register i;
--- 15,21 ----
double number;
char *buf;
{
! int sign, decpt, len;
register char *p1, *p2;
register i;
***************
*** 22,27 ****
--- 23,37 ----
p2 = buf;
if (sign)
*p2++ = '-';
+ len = strlen(p2);
+ if(ndigit > len)
+ ndigit = len;
+ if(ndigit == 0)
+ {
+ buf[0] = '0';
+ buf[1] = '\0';
+ return buf;
+ }
for (i=ndigit-1; i>0 && p1[i]=='0'; i--)
ndigit--;
if (decpt >= 0 && decpt-ndigit > 4
***************
*** 37,42 ****
--- 47,58 ----
*p2++ = '-';
} else
*p2++ = '+';
+ #ifndef vax
+ if(decpt >= 100) {
+ *p2++ = decpt/100 + '0';
+ *p2++ = (decpt%100)/10 + '0';
+ } else
+ #endif
*p2++ = decpt/10 + '0';
*p2++ = decpt%10 + '0';
} else {
*** /source/bsd-4.3/rt/lib/libc/ca/gen/ecvt.c Tue Sep 19 14:20:16 1989
--- ecvt.c Wed Mar 7 21:12:45 1990
***************
*** 398,404 ****
/* tnf is the ASCII character form of the result significand. */
! static char tnf[27];
/* tnh is a little less than half the difference between any two
consecutive numbers having the same exponent as the argument, and
--- 398,404 ----
/* tnf is the ASCII character form of the result significand. */
! static char tnf[32];
/* tnh is a little less than half the difference between any two
consecutive numbers having the same exponent as the argument, and