From fd595ebc7ea45aac3389778a2ab7d82054eb4628 Mon Sep 17 00:00:00 2001 From: Evan Overman Date: Sat, 10 Jun 2023 12:10:08 -0700 Subject: [PATCH] fix memory reporting with bad cast --- src/main.c | 3 ++- src/sysinf.c | 4 ++-- src/sysinf.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 14766c4..7033194 100644 --- a/src/main.c +++ b/src/main.c @@ -69,7 +69,8 @@ int main(int argc, char** argv) { // This is every variable outputted as part of the fetch. unsigned long stor_capacity, stor_used; - unsigned int longest_entry_len, mem_capacity_u; + unsigned int longest_entry_len; + long mem_capacity_u; double stor_capacity_dec, stor_used_dec, mem_capacity; char * stor_unit, * mem_unit, * kern_version, * host_name, cpu_model[1024]; const char* pac_man = NULL; diff --git a/src/sysinf.c b/src/sysinf.c index 924a6d7..0066e12 100644 --- a/src/sysinf.c +++ b/src/sysinf.c @@ -45,7 +45,7 @@ sysinf_err_t get_root_size(unsigned long* size, unsigned long* usage) { return SI_ERR_NONE; } -sysinf_err_t get_memory_capacity(unsigned int* mem_cap) { +sysinf_err_t get_memory_capacity(long* mem_cap) { char mem_capacity_str[64]; FILE* meminfo = fopen("/proc/meminfo", "r"); @@ -85,7 +85,7 @@ sysinf_err_t get_memory_capacity(unsigned int* mem_cap) { return SI_ERR_COULD_NOT_READ; } - *mem_cap = (unsigned int)atol(mem_capacity_str) * 1000; + *mem_cap = atol(mem_capacity_str) * 1000; return SI_ERR_NONE; } diff --git a/src/sysinf.h b/src/sysinf.h index 3bd885c..0f5fa06 100644 --- a/src/sysinf.h +++ b/src/sysinf.h @@ -46,6 +46,6 @@ sysinf_err_t get_root_size(unsigned long* size, unsigned long* usage); /// /// @returns /// sysinf_err_t -sysinf_err_t get_memory_capacity(unsigned int* mem_cap); +sysinf_err_t get_memory_capacity(long* mem_cap); #endif // SYSINF_H