From c5a9b9d42841a125819dfe0842ed8a6989ba1337 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 19 Feb 2021 10:07:00 +0100 Subject: [PATCH] fixed a bug that caused segfault with -O3 --- src/battery.c | 6 +++--- src/cpu.c | 2 +- src/disk.c | 2 +- src/memory.c | 18 +++++++++--------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/battery.c b/src/battery.c index 858b3fd7c..ae32b0bff 100644 --- a/src/battery.c +++ b/src/battery.c @@ -8,7 +8,7 @@ void ffPrintBattery(FFstate* state) if(fullFile == NULL) return; uint32_t full; - scanned = fscanf(fullFile, "%lu", &full); + scanned = fscanf(fullFile, "%u", &full); if(scanned != 1) return; fclose(fullFile); @@ -17,7 +17,7 @@ void ffPrintBattery(FFstate* state) if(nowFile == NULL) return; uint32_t now; - scanned = fscanf(nowFile, "%lu", &now); + scanned = fscanf(nowFile, "%u", &now); if(scanned != 1) return; fclose(nowFile); @@ -34,5 +34,5 @@ void ffPrintBattery(FFstate* state) uint32_t percentage = (now / (double) full) * 100; ffPrintLogoAndKey(state, "Battery"); - printf("%lu%% [%s]\n", percentage, status); + printf("%u%% [%s]\n", percentage, status); } \ No newline at end of file diff --git a/src/cpu.c b/src/cpu.c index 07439bcb3..fe538c902 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -13,7 +13,7 @@ void ffPrintCPU(FFstate* state) char cores[256]; uint32_t hz; - sscanf(frequency, "%ul", &hz); //in KHz + sscanf(frequency, "%u", &hz); //in KHz hz /= 1000; //to MHz double ghz = (double) hz / 1000.0; //to GHz diff --git a/src/disk.c b/src/disk.c index aa63592a5..35ff9b6a6 100644 --- a/src/disk.c +++ b/src/disk.c @@ -20,5 +20,5 @@ void ffPrintDisk(FFstate* state) ffPrintLogoAndKey(state, "Disk (/)"); - printf("%luGB / %luGB (%lu%%)\n", used, total, percentage); + printf("%uGB / %uGB (%u%%)\n", used, total, percentage); } \ No newline at end of file diff --git a/src/memory.c b/src/memory.c index 015785a38..56804da58 100644 --- a/src/memory.c +++ b/src/memory.c @@ -5,24 +5,24 @@ void ffPrintMemory(FFstate* state) { ffPrintLogoAndKey(state, "Memory"); - FILE *meminfo = fopen("/proc/meminfo", "r"); + FILE* meminfo = fopen("/proc/meminfo", "r"); if(meminfo == NULL) { printf("[Error opening /proc/meminfo\n"); return; } - char *line = NULL; + char* line = NULL; size_t len; uint32_t total, shared, memfree, buffers, cached, reclaimable; while (getline(&line, &len, meminfo) != -1) { - sscanf(line, "MemTotal: %lu", &total); - sscanf(line, "Shmem: %lu", &shared); - sscanf(line, "MemFree: %lu", &memfree); - sscanf(line, "Buffers: %lu", &buffers); - sscanf(line, "Cached: %lu", &cached); - sscanf(line, "SReclaimable: %lu", &reclaimable); + sscanf(line, "MemTotal: %u", &total); + sscanf(line, "Shmem: %u", &shared); + sscanf(line, "MemFree: %u", &memfree); + sscanf(line, "Buffers: %u", &buffers); + sscanf(line, "Cached: %u", &cached); + sscanf(line, "SReclaimable: %u", &reclaimable); } free(line); @@ -32,5 +32,5 @@ void ffPrintMemory(FFstate* state) uint32_t total_mem = total / 1024; uint8_t percentage = (uint8_t) ((used_mem / (double) total_mem) * 100); - printf("%luMiB / %luMiB (%u%%)\n", used_mem, total_mem, percentage); + printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage); } \ No newline at end of file