diff --git a/src/common.cc b/src/common.cc index 357a8a7a..4167c37c 100644 --- a/src/common.cc +++ b/src/common.cc @@ -375,6 +375,10 @@ uint8_t cpu_percentage(struct text_object *obj) { } double cpu_barval(struct text_object *obj) { + if (static_cast(obj->data.i) > info.cpu_count) { + NORM_ERR("obj->data.i %i info.cpu_count %i", obj->data.i, info.cpu_count); + CRIT_ERR(nullptr, nullptr, "attempting to use more CPUs than you have!"); + } if (info.cpu_usage != nullptr) { return info.cpu_usage[obj->data.i]; } return 0.; } diff --git a/tests/test-common.cc b/tests/test-common.cc index 3f227e4c..eefca57d 100644 --- a/tests/test-common.cc +++ b/tests/test-common.cc @@ -160,11 +160,10 @@ TEST_CASE("cpu_percentage and cpu_barval return correct values") { info.cpu_usage[0] = 0.253; info.cpu_usage[1] = 0.507; - REQUIRE(cpu_barval(&obj2) == 0); - // This does not exist in Catch2, but would be nice to have since that's // what happens in this case. // REQUIRE_EXIT(cpu_percentage(&obj2)); + // REQUIRE_EXIT(cpu_barval(&obj2)); delete[] info.cpu_usage; }