From 35f7862744288411600b5200e3612b4ed204092d Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Wed, 14 Sep 2016 16:20:20 +0300 Subject: [PATCH 1/2] simplified run_command() --- slstatus.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/slstatus.c b/slstatus.c index fefdf6f..1a297f8 100644 --- a/slstatus.c +++ b/slstatus.c @@ -406,26 +406,18 @@ ram_used(void) static char * run_command(const char* command) { - int good; FILE *fp = popen(command, "r"); - char buffer[64] = ""; + char buffer[64]; if (fp == NULL) { warn("Could not get command output for: %s", command); return smprintf(UNKNOWN_STR); } - fgets(buffer, sizeof(buffer)-1, fp); - pclose(fp); - for (int i = 0 ; i != sizeof(buffer); i++) { - if (buffer[i] == '\0') { - good = 1; - break; - } - } - if (good) - buffer[strlen(buffer)-1] = '\0'; + fgets(buffer, sizeof(buffer), fp); + buffer[sizeof(buffer)-1] = '\0'; + pclose(fp); return smprintf("%s", buffer); } From 561de544e74487f5e7a9b51850d382fe2278a915 Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Wed, 14 Sep 2016 17:42:48 +0300 Subject: [PATCH 2/2] variable initialization is back --- slstatus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slstatus.c b/slstatus.c index 1a297f8..a13bf3b 100644 --- a/slstatus.c +++ b/slstatus.c @@ -407,7 +407,7 @@ static char * run_command(const char* command) { FILE *fp = popen(command, "r"); - char buffer[64]; + char buffer[64] = '\0'; if (fp == NULL) { warn("Could not get command output for: %s", command);