Attention aux debordements de format_buffer avec %f et des grands flottants

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@464 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1995-11-26 11:28:07 +00:00
parent 7c3be71ad9
commit a721810eec
1 changed files with 8 additions and 3 deletions

View File

@ -90,7 +90,12 @@ value copy_double(d)
value format_float(fmt, arg) /* ML */
value fmt, arg;
{
char format_buffer[64];
#define MAX_DIGITS 350
/* Max number of decimal digits in a "natural" (not artificially padded)
representation of a float. Can be quite big for %f format.
Max exponent for IEEE format is 308 decimal digits.
Rounded up for good measure. */
char format_buffer[MAX_DIGITS + 20];
int prec, i;
char * p;
char * dest;
@ -99,14 +104,14 @@ value format_float(fmt, arg) /* ML */
prec = 64;
for (p = String_val(fmt); *p != 0; p++) {
if (*p >= '0' && *p <= '9') {
i = atoi(p) + 15;
i = atoi(p) + MAX_DIGITS;
if (i > prec) prec = i;
break;
}
}
for( ; *p != 0; p++) {
if (*p == '.') {
i = atoi(p+1) + 15;
i = atoi(p+1) + MAX_DIGITS;
if (i > prec) prec = i;
break;
}