From dcb163aa8e7808b59aef3d3319c707e7d9ac4ce4 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 4 Nov 2010 23:22:40 +0100 Subject: powertop: replace erroneous \n with \0; make numberic conversion more robust Signed-off-by: Denys Vlasenko --- procps/powertop.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/procps/powertop.c b/procps/powertop.c index 4c3c3565e..87efbe892 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -323,18 +323,16 @@ static void process_irq_counts(void) */ *p = '\0'; /* Deal with non-maskable interrupts -- make up fake numbers */ - nr = index_in_strings("NMI\0RES\nCAL\0TLB\0TRM\0THR\0SPU\0", buf); - if (nr != -1) { + nr = index_in_strings("NMI\0RES\0CAL\0TLB\0TRM\0THR\0SPU\0", buf); + if (nr >= 0) { nr += 20000; } else { /* bb_strtou doesn't eat leading spaces, using strtoul */ + errno = 0; nr = strtoul(buf, NULL, 10); + if (errno) + continue; } - *p = ':'; - - if (nr == -1) - continue; - p++; /* 0: 143646045 153901007 IO-APIC-edge timer * ^ -- cgit v1.2.3 From dea28e1e558228d9c46cdb25c7f00986d9d52bcc Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Thu, 4 Nov 2010 23:30:11 +0100 Subject: powertop: fix last line detection in process_timer_stats() Signed-off-by: Denys Vlasenko --- procps/powertop.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/procps/powertop.c b/procps/powertop.c index 87efbe892..da7f05258 100644 --- a/procps/powertop.c +++ b/procps/powertop.c @@ -420,12 +420,12 @@ static NOINLINE int process_timer_stats(void) int idx; count = skip_whitespace(buf); - if (strcmp(strchrnul(count, ' '), " total events") == 0) - break; p = strchr(count, ','); if (!p) continue; *p++ = '\0'; + if (strcmp(skip_non_whitespace(count), " total events") == 0) + break; if (strchr(count, 'D')) continue; /* deferred */ p = skip_whitespace(p); /* points to pid now */ -- cgit v1.2.3