Fix a problem formatting very large numbers. (#642)
Avoid walking off the end of an array when trying to format a number larger than 1000T. Motivated by #641, as reported by @shingchuang, but slightly reimplemented.
Этот коммит содержится в:
родитель
2bc3d2ee5d
Коммит
25f5947512
@ -99,5 +99,12 @@ main(int argc, char **argv)
|
||||
unit_snprintf(s, 11, d, 'a');
|
||||
assert(strncmp(s, "35.2 Tbit", 11) == 0);
|
||||
|
||||
d = 4.0 * 1024 * 1024 * 1024 * 1024 * 1024;
|
||||
unit_snprintf(s, 11, d, 'A');
|
||||
assert(strncmp(s, "4096 TByte", 11) == 0);
|
||||
|
||||
unit_snprintf(s, 11, d, 'a');
|
||||
assert(strncmp(s, "36029 Tbit", 11) == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -303,14 +303,14 @@ extern "C"
|
||||
|
||||
if (isupper((int) inFormat))
|
||||
{
|
||||
while (tmpNum >= 1024.0 && conv <= TERA_CONV)
|
||||
while (tmpNum >= 1024.0 && conv < TERA_CONV)
|
||||
{
|
||||
tmpNum /= 1024.0;
|
||||
conv++;
|
||||
}
|
||||
} else
|
||||
{
|
||||
while (tmpNum >= 1000.0 && conv <= TERA_CONV)
|
||||
while (tmpNum >= 1000.0 && conv < TERA_CONV)
|
||||
{
|
||||
tmpNum /= 1000.0;
|
||||
conv++;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user