mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Disk: don't convert NAN to integer; don't print 0B / 0B (0%)
fix ASAN warning: `runtime error: nan is outside the range of representable values of type 'unsigned char'`
This commit is contained in:
+11
-3
@@ -30,23 +30,31 @@ static void printDisk(FFinstance* instance, const FFDisk* disk)
|
||||
ffStrbufInit(&totalPretty);
|
||||
ffParseSize(disk->bytesTotal, instance->config.binaryPrefixType, &totalPretty);
|
||||
|
||||
uint8_t bytesPercentage = disk->bytesTotal > 0 ? (uint8_t) (((long double) disk->bytesUsed / (long double) disk->bytesTotal) * 100.0) : 0;
|
||||
|
||||
if(instance->config.disk.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, key.chars, 0, NULL);
|
||||
printf("%s / %s (%u%%)", usedPretty.chars, totalPretty.chars, disk->bytesPercentage);
|
||||
if(disk->bytesTotal > 0)
|
||||
printf("%s / %s (%u%%)", usedPretty.chars, totalPretty.chars, bytesPercentage);
|
||||
else
|
||||
fputs("unknown", stdout);
|
||||
|
||||
if(disk->type == FF_DISK_TYPE_EXTERNAL)
|
||||
printf(" [Removable]");
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t filesPercentage = disk->filesTotal > 0 ? (uint8_t) (((double) disk->filesUsed / (double) disk->filesTotal) * 100.0) : 0;
|
||||
|
||||
ffPrintFormatString(instance, key.chars, 0, NULL, &instance->config.disk.outputFormat, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &disk->bytesPercentage},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &bytesPercentage},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &disk->filesUsed},
|
||||
{FF_FORMAT_ARG_TYPE_UINT, &disk->filesTotal},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &disk->filesPercentage},
|
||||
{FF_FORMAT_ARG_TYPE_UINT8, &filesPercentage},
|
||||
{FF_FORMAT_ARG_TYPE_BOOL, FF_FORMAT_ARG_VALUE_BOOL(disk->type == FF_DISK_TYPE_EXTERNAL)},
|
||||
{FF_FORMAT_ARG_TYPE_BOOL, FF_FORMAT_ARG_VALUE_BOOL(disk->type == FF_DISK_TYPE_HIDDEN)},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &disk->filesystem},
|
||||
|
||||
Reference in New Issue
Block a user