From e056dca8f16696387b1710c4201eb65b252774b8 Mon Sep 17 00:00:00 2001 From: icanhasserver Date: Sat, 14 May 2016 19:41:35 +0200 Subject: [PATCH] Increase info.cpu_count for single-core systems (#257) On single-core systems, sscanf() does't match, as the sysfs file contains the value 0 instead of i.e. 0-7 for multi-core systems. --- src/linux.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/linux.cc b/src/linux.cc index ddc9bd24..40bf4bd9 100644 --- a/src/linux.cc +++ b/src/linux.cc @@ -820,9 +820,10 @@ void get_cpu_count(void) } if (sscanf(buf, "%*d-%d", &highest_cpu_index) == 1) { - info.cpu_count = highest_cpu_index + 1; + info.cpu_count = highest_cpu_index; } } + ++info.cpu_count; info.cpu_usage = (float*)malloc((info.cpu_count + 1) * sizeof(float)); fclose(stat_fp);