From: Igor Zhbanov <i.zhbanov at samsung.com>
To: powertop@lists.01.org
Subject: [Powertop] Device list sort function bug
Date: Wed, 11 Jul 2012 10:11:16 +0400 [thread overview]
Message-ID: <4FFD1904.7040804@samsung.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]
Hello!
Sometimes PowerTOP dies with a Segmentation Fault while generating
the report. Little investigation shown that it dies while sorting
the device list. The problem is that comparison function devlist_sort
is incorrect.
The function should return true if first argument "preceeds" second.
But when strcmp() is used, it can return -1, 0 and 1. So both -1 and 1
values are silently converted to true, which is wrong. It confuses the sort()
function and it crosses boundary of array.
Here is the patch:
--8<--Cut-here----------------------------------------------------------------
diff -purN powertop-il/src/devlist.cpp powertop-il-fix/src/devlist.cpp
--- powertop-il/src/devlist.cpp 2012-07-03 17:00:50.000000000 +0400
+++ powertop-il-fix/src/devlist.cpp 2012-07-03 20:01:05.896232845 +0400
@@ -273,7 +273,7 @@ static bool devlist_sort(struct devuser
if (i->pid != j->pid)
return i->pid< j->pid;
- return strcmp(i->device, j->device);
+ return (strcmp(i->device, j->device)< 0);
}
static const char *dev_class(int line)
--8<--------------------------------------------------------------------------
Thank you.
--
Best regards,
Igor Zhbanov,
Expert Software Engineer,
phone: +7 (495) 797 25 00 ext 3806
e-mail: i.zhbanov(a)samsung.com
ASWG, Moscow R&D center, Samsung Electronics
12 Dvintsev street, building 1
127018, Moscow, Russian Federation
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 03-powertop-fix01.diff --]
[-- Type: text/x-diff, Size: 453 bytes --]
diff -purN powertop-il/src/devlist.cpp powertop-il-fix/src/devlist.cpp
--- powertop-il/src/devlist.cpp 2012-07-03 17:00:50.000000000 +0400
+++ powertop-il-fix/src/devlist.cpp 2012-07-03 20:01:05.896232845 +0400
@@ -273,7 +273,7 @@ static bool devlist_sort(struct devuser
if (i->pid != j->pid)
return i->pid < j->pid;
- return strcmp(i->device, j->device);
+ return (strcmp(i->device, j->device) < 0);
}
static const char *dev_class(int line)
next reply other threads:[~2012-07-11 6:11 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-11 6:11 Igor Zhbanov [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-07-11 7:33 [Powertop] Device list sort function bug Sergey Senozhatsky
2012-07-11 7:52 Paul Menzel
2012-07-11 7:55
2012-07-11 8:16 Igor Zhbanov
2012-07-11 8:57 Paul Menzel
2012-07-11 14:43
2012-07-17 22:09 Chris Ferron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4FFD1904.7040804@samsung.com \
--to=powertop@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.