From 0d6674b9b9abe459b5b76ed84b5eda7fdb42757e Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Fri, 29 Apr 2022 11:50:13 -0400 Subject: [PATCH] Remove trailing kB from proc/meminfo --- src/components/memory.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/memory.cpp b/src/components/memory.cpp index 118b406..74b396e 100644 --- a/src/components/memory.cpp +++ b/src/components/memory.cpp @@ -13,14 +13,17 @@ bool memory::getProcMem(crow::json::wvalue& ret){ while(std::getline(f, line)){ size_t colon; int last_space = -1; + int final_space = -1; for(int i = 0; line[i] != '\0' ; ++i){ if(line[i] == ':') colon = i; - else if(line[i-1] == ' ' && line[i] != ' ' && last_space == -1) + else if(last_space == -1 && line[i-1] == ' ' && line[i] != ' ' ) last_space = i; + else if(last_space != -1 && line[i] == ' ') + final_space = i; } - ret[line.substr(0,colon)] = line.substr(last_space); + ret[line.substr(0,colon)] = line.substr(last_space, final_space - last_space); } } else { ret["message"] = "Failed to open proc filesystem";