about summary refs log tree commit diff
path: root/analyzer
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-07-27 02:04:15 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2013-07-27 02:04:15 +0000
commit3abf635c6b3950a15b52afc04a198eca86719e1a (patch)
treed34e067410499370845eadd1aa793ec9dfd942a5 /analyzer
parentcc8fb06ac03a5797c5fb27f3cca61fe705144cbd (diff)
downloadnetpbm-mirror-3abf635c6b3950a15b52afc04a198eca86719e1a.tar.gz
netpbm-mirror-3abf635c6b3950a15b52afc04a198eca86719e1a.tar.xz
netpbm-mirror-3abf635c6b3950a15b52afc04a198eca86719e1a.zip
Fix abuse of unsigned integer coercion to integer
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1997 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'analyzer')
-rw-r--r--analyzer/ppmhist.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/analyzer/ppmhist.c b/analyzer/ppmhist.c
index 321e4b3a..2f6c9348 100644
--- a/analyzer/ppmhist.c
+++ b/analyzer/ppmhist.c
@@ -100,39 +100,61 @@ parseCommandLine(int argc, const char ** argv,
 
 
 
+static int
+cmpUint(unsigned int const a,
+        unsigned int const b) {
+/*----------------------------------------------------------------------------
+   Return 1 if 'a' > 'b'; -1 if 'a' is < 'b'; 0 if 'a' == 'b'.
+
+   I.e. what a libc qsort() comparison function returns.
+-----------------------------------------------------------------------------*/
+    return a > b ? 1 : a < b ? -1 : 0;
+}
+
+
+
 #ifndef LITERAL_FN_DEF_MATCH
-static qsort_comparison_fn cmpfn;
+static qsort_comparison_fn countcompare;
 #endif
 
+
 static int
-countcompare(const void *ch1, const void *ch2) {
+countcompare(const void * const a,
+             const void * const b) {
 /*----------------------------------------------------------------------------
    This is a 'qsort' collation function.
 -----------------------------------------------------------------------------*/
-    return ((colorhist_vector)ch2)->value - ((colorhist_vector)ch1)->value;
+    const struct colorhist_item * const histItem1P = a;
+    const struct colorhist_item * const histItem2P = b;
+
+    return cmpUint(histItem2P->value, histItem1P->value);
 }
 
 
 
 #ifndef LITERAL_FN_DEF_MATCH
-static qsort_comparison_fn cmpfn;
+static qsort_comparison_fn rgbcompare;
 #endif
 
 static int
-rgbcompare(const void * arg1, const void * arg2) {
+rgbcompare(const void * const a,
+           const void * const b) {
 /*----------------------------------------------------------------------------
    This is a 'qsort' collation function.
 -----------------------------------------------------------------------------*/
-    colorhist_vector const ch1 = (colorhist_vector) arg1;
-    colorhist_vector const ch2 = (colorhist_vector) arg2;
+    const struct colorhist_item * const histItem1P = a;
+    const struct colorhist_item * const histItem2P = b;
 
     int retval;
 
-    retval = (PPM_GETR(ch1->color) - PPM_GETR(ch2->color));
+    retval = cmpUint(PPM_GETR(histItem1P->color),
+                     PPM_GETR(histItem2P->color));
     if (retval == 0) {
-        retval = (PPM_GETG(ch1->color) - PPM_GETG(ch2->color));
+        retval = cmpUint(PPM_GETG(histItem1P->color),
+                         PPM_GETG(histItem2P->color));
         if (retval == 0)
-            retval = (PPM_GETB(ch1->color) - PPM_GETB(ch2->color));
+            retval = cmpUint(PPM_GETB(histItem1P->color),
+                             PPM_GETB(histItem2P->color));
     }
     return retval;
 }