From: ceriel Date: Thu, 5 Feb 1987 20:47:30 +0000 (+0000) Subject: array bound check added X-Git-Tag: release-5-5~4742 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=060a309f8233c88e02d8dea6f8cd40a863f47056;p=ack.git array bound check added --- diff --git a/lang/cem/libcc/gen/ecvt.c b/lang/cem/libcc/gen/ecvt.c index 0217eb101..4be5e6653 100644 --- a/lang/cem/libcc/gen/ecvt.c +++ b/lang/cem/libcc/gen/ecvt.c @@ -28,12 +28,12 @@ cvt(value, ndigit, decpt, sign, ecvtflag) static char buf[NDIGITS]; char buf1[NDIGITS]; register char *pe = buf1; - register char *pb = buf; + register char *pb; int pointpos = 0; if (ndigit < 0) ndigit = 0; - if (ndigit >= NDIGITS - 1) ndigit = NDIGITS - 2; + if (ndigit >= NDIGITS - 10) ndigit = NDIGITS - 11; *sign = 0; if (value < 0) { @@ -50,6 +50,11 @@ cvt(value, ndigit, decpt, sign, ecvtflag) /* compensate for rounding errors, because the conversion to "int" truncates */ + if (pe >= &buf1[NDIGITS]) { + pb = &buf1[NDIGITS-10]; + while (pb > buf1) *--pb = *--pe; + pe = &buf[NDIGITS-10]; + } *pe++ = (int)((value+.05) * 10) + '0'; pointpos++; } while (intpart != 0); @@ -61,6 +66,7 @@ cvt(value, ndigit, decpt, sign, ecvtflag) fractpart = value; pointpos--; } + pb = &buf[0]; } pe = &buf[ndigit]; if (! ecvtflag) {