From 4d37d021e1ce00b499b6f032027d94178f7ee8c5 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sat, 25 Jul 2009 14:36:55 +0200 Subject: [PATCH] Handle if popen should fail --- src/conky.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/conky.c b/src/conky.c index 64f5070d..b19ea8ea 100644 --- a/src/conky.c +++ b/src/conky.c @@ -642,12 +642,16 @@ static struct text_object global_root_object; static inline void read_exec(const char *data, char *buf, const int size) { FILE *fp = popen(data, "r"); - int length = fread(buf, 1, size, fp); + if(fp) { + int length = fread(buf, 1, size, fp); - pclose(fp); - buf[length] = '\0'; - if (length > 0 && buf[length - 1] == '\n') { - buf[length - 1] = '\0'; + pclose(fp); + buf[length] = '\0'; + if (length > 0 && buf[length - 1] == '\n') { + buf[length - 1] = '\0'; + } + } else { + buf[0] = '\0'; } }