array bound check added
authorceriel <none@none>
Thu, 5 Feb 1987 20:47:30 +0000 (20:47 +0000)
committerceriel <none@none>
Thu, 5 Feb 1987 20:47:30 +0000 (20:47 +0000)
lang/cem/libcc/gen/ecvt.c

index 0217eb1..4be5e66 100644 (file)
@@ -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) {