From 8f216f7e60ffcc25b77a76cb3900a39a2d67816c Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 25 Sep 2012 19:03:41 +0200 Subject: [PATCH] remove cases of equal comparison for qsort() Returning 0 (equal) can lead to undefined behaviour. And, in our cases we'll never have equal keys (added asserts for that) Change-Id: Ifaf202df321d3f877ad2a03de42e0d6cdd1b2388 --- src/enc/vp8l.c | 3 ++- src/utils/huffman_encode.c | 9 ++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/enc/vp8l.c b/src/enc/vp8l.c index 9c202f8d..affd91ce 100644 --- a/src/enc/vp8l.c +++ b/src/enc/vp8l.c @@ -37,7 +37,8 @@ extern "C" { static int CompareColors(const void* p1, const void* p2) { const uint32_t a = *(const uint32_t*)p1; const uint32_t b = *(const uint32_t*)p2; - return (a < b) ? -1 : (a > b) ? 1 : 0; + assert(a != b); + return (a < b) ? -1 : 1; } // If number of colors in the image is less than or equal to MAX_PALETTE_SIZE, diff --git a/src/utils/huffman_encode.c b/src/utils/huffman_encode.c index 8ccd291d..d4715687 100644 --- a/src/utils/huffman_encode.c +++ b/src/utils/huffman_encode.c @@ -138,13 +138,8 @@ static int CompareHuffmanTrees(const void* ptr1, const void* ptr2) { } else if (t1->total_count_ < t2->total_count_) { return 1; } else { - if (t1->value_ < t2->value_) { - return -1; - } - if (t1->value_ > t2->value_) { - return 1; - } - return 0; + assert(t1->value_ != t2->value_); + return (t1->value_ < t2->value_) ? -1 : 1; } }