mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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
1 changed files with 5 additions and 3 deletions
|
@ -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 */
|
||||
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;
|
||||
char *e;
|
||||
const int mode = digs == 0 ? 0 : 2;
|
||||
char *p = BigDecimal_dtoa(d, mode, (int)digs, &decpt, &negative_p, &e);
|
||||
int len10 = (int)(e - p);
|
||||
if (len10 >= (int)sizeof(buf))
|
||||
len10 = (int)sizeof(buf) - 1;
|
||||
if (len10 > DBLE_FIG) {
|
||||
/* TODO: Presumably, rounding should be done here. */
|
||||
len10 = DBLE_FIG;
|
||||
}
|
||||
memcpy(buf, p, len10);
|
||||
xfree(p);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue