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-0dff7051ff02master
parent
7c3be71ad9
commit
a721810eec
|
@ -90,7 +90,12 @@ value copy_double(d)
|
||||||
value format_float(fmt, arg) /* ML */
|
value format_float(fmt, arg) /* ML */
|
||||||
value fmt, arg;
|
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;
|
int prec, i;
|
||||||
char * p;
|
char * p;
|
||||||
char * dest;
|
char * dest;
|
||||||
|
@ -99,14 +104,14 @@ value format_float(fmt, arg) /* ML */
|
||||||
prec = 64;
|
prec = 64;
|
||||||
for (p = String_val(fmt); *p != 0; p++) {
|
for (p = String_val(fmt); *p != 0; p++) {
|
||||||
if (*p >= '0' && *p <= '9') {
|
if (*p >= '0' && *p <= '9') {
|
||||||
i = atoi(p) + 15;
|
i = atoi(p) + MAX_DIGITS;
|
||||||
if (i > prec) prec = i;
|
if (i > prec) prec = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for( ; *p != 0; p++) {
|
for( ; *p != 0; p++) {
|
||||||
if (*p == '.') {
|
if (*p == '.') {
|
||||||
i = atoi(p+1) + 15;
|
i = atoi(p+1) + MAX_DIGITS;
|
||||||
if (i > prec) prec = i;
|
if (i > prec) prec = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue