From 25eac4c0e59b0cf0bf076db3db500cccb3219379 Mon Sep 17 00:00:00 2001 From: su8 Date: Mon, 6 Aug 2018 10:42:08 +0200 Subject: [PATCH] top.cc: Dont crash on null, and fix for https://github.com/brndnmtthws/conky/issues/220 --- src/top.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/top.cc b/src/top.cc index a6e6082b..a67e169b 100644 --- a/src/top.cc +++ b/src/top.cc @@ -535,13 +535,19 @@ static void print_top_time(struct text_object *obj, char *p, int p_max_size) { static void print_top_user(struct text_object *obj, char *p, int p_max_size) { auto *td = static_cast(obj->data.opaque); + struct passwd *pw; if ((td == nullptr) || (td->list == nullptr) || (td->list[td->num] == nullptr)) { return; } - snprintf(p, p_max_size, "%.8s", getpwuid(td->list[td->num]->uid)->pw_name); + pw = getpwuid(td->list[td->num]->uid); + if (pw != nullptr) { + snprintf(p, p_max_size, "%.8s", pw->pw_name); + } else { + NORM_ERR("The uid doesn't exist"); + } } #define PRINT_TOP_GENERATOR(name, width, fmt, field) \