diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c index 015c401e..4c4467ee 100644 --- a/cmds/filesystem-usage.c +++ b/cmds/filesystem-usage.c @@ -1302,10 +1302,19 @@ void print_device_chunks(const struct device_info *devinfo, allocated += size; } - pr_verbose(LOG_DEFAULT, " Unallocated: %*s%10s\n", - (int)(20 - strlen("Unallocated")), "", - pretty_size_mode(devinfo->size - allocated, - unit_mode | UNITS_NEGATIVE)); + + /* + * If chunkinfos is empty, we cannot compute the unallocated size, so + * don't print incorrect data. + */ + if (chunkinfos->length == 0) + pr_verbose(LOG_DEFAULT, " Unallocated: %*s%10s\n", + (int)(20 - strlen("Unallocated")), "", "N/A"); + else + pr_verbose(LOG_DEFAULT, " Unallocated: %*s%10s\n", + (int)(20 - strlen("Unallocated")), "", + pretty_size_mode(devinfo->size - allocated, + unit_mode | UNITS_NEGATIVE)); } void print_device_sizes(const struct device_info *devinfo, unsigned unit_mode)