aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Zhbanov <i.zhbanov@samsung.com>2012-07-11 12:16:33 +0400
committerChris E Ferron <chris.e.ferron@linux.intel.com>2012-07-17 14:13:07 -0700
commit240a4d854679023850d3de44757819163d468979 (patch)
tree8eff8f5dac65a55a6d6e2cf59a56e8f9f1896043
parentc52170a5e08dfb5fab256a56a1fac3dc58954555 (diff)
Device list sort function bug
So here is the formatted version: From 5d284137a6035bab65717fbacd98423b96d862cf Mon Sep 17 00:00:00 2001 From: Igor Zhbanov<i.zhbanov@samsung.com> Date: Wed, 11 Jul 2012 12:08:21 +0400 Subject: [PATCH] Device list sort function bug 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.
-rw-r--r--src/devlist.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/devlist.cpp b/src/devlist.cpp
index 93f2081..dc4f569 100644
--- a/src/devlist.cpp
+++ b/src/devlist.cpp
@@ -273,7 +273,7 @@ static bool devlist_sort(struct devuser * i, struct devuser * j)
if (i->pid != j->pid)
return i->pid < j->pid;
- return strcmp(i->device, j->device);
+ return (strcmp(i->device, j->device)< 0)< 0)< 0)< 0)< 0)< 0)< 0)< 0)< 0);
}
static const char *dev_class(int line)