From 25680305095bfcedaa46cb017182544183ab743b Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Tue, 5 Jan 2010 16:59:50 +0100 Subject: [PATCH] Fix sigsegv if cpu_usage has not yet been populated (seen on 1.8.0_rc1) --- src/common.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common.cc b/src/common.cc index 35c044ee..ef1feb38 100644 --- a/src/common.cc +++ b/src/common.cc @@ -494,12 +494,20 @@ uint8_t cpu_percentage(struct text_object *obj) obj->data.i, info.cpu_count); CRIT_ERR(NULL, NULL, "attempting to use more CPUs than you have!"); } - return round_to_int(info.cpu_usage[obj->data.i] * 100.0); + if (info.cpu_usage) { + return round_to_int(info.cpu_usage[obj->data.i] * 100.0); + } else { + return 0; + } } double cpu_barval(struct text_object *obj) { - return info.cpu_usage[obj->data.i]; + if (info.cpu_usage) { + return info.cpu_usage[obj->data.i]; + } else { + return 0.; + } } #define PRINT_HR_GENERATOR(name) \