diff options
author | norly <ny-git@enpas.org> | 2016-07-05 23:45:47 +0200 |
---|---|---|
committer | norly <ny-git@enpas.org> | 2016-07-05 23:55:10 +0200 |
commit | 595d73bdbece9274f8d7fdbdb9346745cf9c41ea (patch) | |
tree | 468e818a0d08d7b4cfed33b6bd9241031209cbbf /src/status/memusage.c | |
parent | c0aab7f93c279121ff8c0fd3efbad8c2fa499595 (diff) |
memusage.c: Read 64-bit integers
This code overflows when installing too much RAM...
Diffstat (limited to 'src/status/memusage.c')
-rw-r--r-- | src/status/memusage.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/status/memusage.c b/src/status/memusage.c index 15523de..d8a9de5 100644 --- a/src/status/memusage.c +++ b/src/status/memusage.c @@ -15,11 +15,11 @@ void status_memusage(GlobalData *g) size_t stlen; FILE *stfile; - int memtotal = 0; - int memfree = 0; - int memused; - int membuffers = 0; - int memcached = 0; + long long memtotal = 0; + long long memfree = 0; + long long memused; + long long membuffers = 0; + long long memcached = 0; statusitem_init(&s); @@ -28,19 +28,19 @@ void status_memusage(GlobalData *g) stfile = fopen("/proc/meminfo", "r"); if (stfile != NULL) { stlen = getline(&stline, &stlen, stfile); - memtotal = atoi(&stline[17]); + memtotal = atoll(&stline[16]); stlen = getline(&stline, &stlen, stfile); - memfree = atoi(&stline[17]); + memfree = atoll(&stline[16]); stlen = getline(&stline, &stlen, stfile); if (stlen > 13 && !memcmp(stline, "MemAvailable:", 13)) { stlen = getline(&stline, &stlen, stfile); } - membuffers = atoi(&stline[17]); + membuffers = atoll(&stline[16]); stlen = getline(&stline, &stlen, stfile); - memcached = atoi(&stline[17]); + memcached = atoll(&stline[16]); free(stline); fclose(stfile); @@ -56,7 +56,7 @@ void status_memusage(GlobalData *g) s.color = "#FF0000"; // red } - snprintf(text, sizeof(text), "Mem: %d M", memused); + snprintf(text, sizeof(text), "Mem: %lld M", memused); line_append_item(g, &s); } |