gdu hangs when entering a directory in which all the files have a size of 0
Steps to reproduce the behavior:
mkdir /tmp/gdu_test
touch /tmp/gdu_test/empty_file.txt
gdu /tmp/gdu_test
The bug is in the following code from tui/format.go:
case ui.ShowApparentSize:
part = int(float64(item.GetSize()) / float64(maxSize) * 100.0)
default:
part = int(float64(item.GetUsage()) / float64(maxUsage) * 100.0)
When all the items in the target directory have a size of 0, then maxSize/maxUsage = 0. Also, item.GetSize() and item.GetUsage() are equal to 0. This results in a 0/0 division, which equals NaN. Then, the casting to int results in the following number: -9223372036854775808.
If at least one file in the target directory has a size > 0, then the bug is not triggered. This is because maxSize/maxUsage are > 0, which avoids dividing by 0.
Description:
gdu hangs when entering a directory in which all the files have a size of 0
Steps to reproduce the behavior:
The bug is in the following code from tui/format.go:
When all the items in the target directory have a size of 0, then maxSize/maxUsage = 0. Also, item.GetSize() and item.GetUsage() are equal to 0. This results in a 0/0 division, which equals NaN. Then, the casting to int results in the following number: -9223372036854775808.
If at least one file in the target directory has a size > 0, then the bug is not triggered. This is because maxSize/maxUsage are > 0, which avoids dividing by 0.