mirror of
https://code.blicky.net/yorhel/ncdu.git
synced 2026-01-14 09:48:40 -09:00
util.c: Fix possible buffer overflow in fillsize() and formatsize()
They should now be able to cope with file sizes in the full (positive) range of a signed integer, i.e. 0 bytes to 8 EiB minus one byte. The size calculation of directories, however, may still overflow and cause negative integers to be passed around. That should be fixed.
This commit is contained in:
parent
3fd25ffbcb
commit
2bc1b3e479
1 changed files with 5 additions and 3 deletions
|
|
@ -62,15 +62,17 @@ char *formatsize(int64_t from) {
|
||||||
else if(r < 1023e3f) { c = 'K'; r/=1024.0f; }
|
else if(r < 1023e3f) { c = 'K'; r/=1024.0f; }
|
||||||
else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; }
|
else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; }
|
||||||
else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; }
|
else if(r < 1023e9f) { c = 'G'; r/=1073741824.0f; }
|
||||||
else { c = 'T'; r/=1099511627776.0f; }
|
else if(r < 1023e12f){ c = 'T'; r/=1099511627776.0f; }
|
||||||
|
else if(r < 1023e15f){ c = 'P'; r/=1125899906842624.0f; }
|
||||||
|
else { c = 'E'; r/=1152921504606846976.0f; }
|
||||||
sprintf(dat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i');
|
sprintf(dat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i');
|
||||||
return dat;
|
return dat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *fullsize(int64_t from) {
|
char *fullsize(int64_t from) {
|
||||||
static char dat[20]; /* max: 999.999.999.999.999 */
|
static char dat[26]; /* max: 9.223.372.036.854.775.807 (= 2^63-1) */
|
||||||
char tmp[20];
|
char tmp[26];
|
||||||
int64_t n = from;
|
int64_t n = from;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue