Skip to content

Commit

Permalink
Merge pull request #318 from gportay/fix-invalid-cpu-placeholder
Browse files Browse the repository at this point in the history
print_cpu_usage: fix invalid %cpu placeholder output
  • Loading branch information
Airblader authored Oct 26, 2018
2 parents 13f720a + aa572d2 commit be5f38e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/print_cpu_usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions testcases/024-cpu-usage-invalid-cpu/expected_output.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env perl

use v5.10;
use strict;
use warnings;

print "CPU: \n";
9 changes: 9 additions & 0 deletions testcases/024-cpu-usage-invalid-cpu/i3status.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
general {
output_format = "none"
}

order += "cpu_usage"

cpu_usage {
format = "CPU: %cpu"
}

0 comments on commit be5f38e

Please sign in to comment.