summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/print_cpu_usage.c2
-rw-r--r--testcases/024-cpu-usage-invalid-cpu/expected_output.pl7
-rw-r--r--testcases/024-cpu-usage-invalid-cpu/i3status.conf9
3 files changed, 17 insertions, 1 deletions
diff --git a/src/print_cpu_usage.c b/src/print_cpu_usage.c
index 1fccba4..411d5f4 100644
--- a/src/print_cpu_usage.c
+++ b/src/print_cpu_usage.c
@@ -151,7 +151,7 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const
}
#if defined(LINUX)
else if (BEGINS_WITH(walk + 1, "cpu")) {
- int number = 0;
+ int number = -1;
sscanf(walk + 1, "cpu%d", &number);
if (number < 0 || number >= cpu_count) {
fprintf(stderr, "provided CPU number '%d' above detected number of CPU %d\n", number, cpu_count);
diff --git a/testcases/024-cpu-usage-invalid-cpu/expected_output.pl b/testcases/024-cpu-usage-invalid-cpu/expected_output.pl
new file mode 100644
index 0000000..45111a6
--- /dev/null
+++ b/testcases/024-cpu-usage-invalid-cpu/expected_output.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+
+use v5.10;
+use strict;
+use warnings;
+
+print "CPU: \n";
diff --git a/testcases/024-cpu-usage-invalid-cpu/i3status.conf b/testcases/024-cpu-usage-invalid-cpu/i3status.conf
new file mode 100644
index 0000000..d32784f
--- /dev/null
+++ b/testcases/024-cpu-usage-invalid-cpu/i3status.conf
@@ -0,0 +1,9 @@
+general {
+ output_format = "none"
+}
+
+order += "cpu_usage"
+
+cpu_usage {
+ format = "CPU: %cpu"
+}