Fix crash when formatting constant wider than 1023 bits (#2260)

This commit is contained in:
Geza Lore
2020-04-14 18:07:09 -04:00
committed by GitHub
parent 5c966ec510
commit 08b74e5ab9
4 changed files with 52 additions and 3 deletions
+6 -3
View File
@@ -583,9 +583,12 @@ string V3Number::displayed(FileLine* fl, const string& vformat) const {
case 'd': { // Unsigned decimal
bool issigned = (code == '~');
if (fmtsize == "") {
double mantissabits = this->width() - (issigned?1:0);
double maxval = pow(2.0, mantissabits);
double dchars = log10(maxval)+1.0;
const double mantissabits = this->width() - (issigned ? 1 : 0);
// To get the number of digits required, we want to compute
// log10(2**mantissabits) and round it up. To be able to handle
// a very wide mantissa, we use log2(2**mantissabits)/log2(10),
// which is simply (+1.0 is for rounding bias):
double dchars = mantissabits / 3.321928094887362 + 1.0;
if (issigned) dchars++; // space for sign
fmtsize = cvtToStr(int(dchars));
}