[ruby/bigdecimal] Fix the maximum length of float number
This change is for preventing the false-positive alert by CoverityScan. See CID-1471770 for the detail. https://github.com/ruby/bigdecimal/commit/4d5b97125b
This commit is contained in:
parent
b4eba8dfee
commit
8df1881c8f
@ -2856,14 +2856,16 @@ rb_float_convert_to_BigDecimal(VALUE val, size_t digs, int raise_exception)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Use the same logic in flo_to_s to convert a float to a decimal string */
|
/* Use the same logic in flo_to_s to convert a float to a decimal string */
|
||||||
char buf[DBLE_FIG + BASE_FIG + 2 + 1];
|
char buf[DBLE_FIG + BASE_FIG + 2 + 1]; /* sizeof(buf) == 28 in the typical case */
|
||||||
int decpt, negative_p;
|
int decpt, negative_p;
|
||||||
char *e;
|
char *e;
|
||||||
const int mode = digs == 0 ? 0 : 2;
|
const int mode = digs == 0 ? 0 : 2;
|
||||||
char *p = BigDecimal_dtoa(d, mode, (int)digs, &decpt, &negative_p, &e);
|
char *p = BigDecimal_dtoa(d, mode, (int)digs, &decpt, &negative_p, &e);
|
||||||
int len10 = (int)(e - p);
|
int len10 = (int)(e - p);
|
||||||
if (len10 >= (int)sizeof(buf))
|
if (len10 > DBLE_FIG) {
|
||||||
len10 = (int)sizeof(buf) - 1;
|
/* TODO: Presumably, rounding should be done here. */
|
||||||
|
len10 = DBLE_FIG;
|
||||||
|
}
|
||||||
memcpy(buf, p, len10);
|
memcpy(buf, p, len10);
|
||||||
xfree(p);
|
xfree(p);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user