about summary refs log tree commit diff
path: root/lib/libpbm3.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-01-12 03:41:56 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-01-12 03:41:56 +0000
commit98f217dd9b7a4c6d1a93b2398ec1e16c61a97cf4 (patch)
tree9b3cc18b7f90337add827befff533f9d6ccb19ea /lib/libpbm3.c
parent41b849297cd0d81229e60a726fe7f1bfad1bc304 (diff)
downloadnetpbm-mirror-98f217dd9b7a4c6d1a93b2398ec1e16c61a97cf4.tar.gz
netpbm-mirror-98f217dd9b7a4c6d1a93b2398ec1e16c61a97cf4.tar.xz
netpbm-mirror-98f217dd9b7a4c6d1a93b2398ec1e16c61a97cf4.zip
Fix negative unsigned integer problem
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@202 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpbm3.c')
-rw-r--r--lib/libpbm3.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/libpbm3.c b/lib/libpbm3.c
index a5d5ea62..a3ada015 100644
--- a/lib/libpbm3.c
+++ b/lib/libpbm3.c
@@ -132,6 +132,14 @@ packBitsWithMmxSse(FILE *          const fileP,
 
 
 
+static unsigned int
+bitValue(unsigned char const byteValue) {
+
+    return byteValue == 0 ? 0 : 1;
+}
+
+
+
 static void
 packBitsGeneric(FILE *          const fileP,
                 const bit *     const bitrow,
@@ -139,27 +147,25 @@ packBitsGeneric(FILE *          const fileP,
                 unsigned int    const cols,
                 unsigned int *  const nextColP) {
 /*----------------------------------------------------------------------------
-   Pack the bits of bitrow[] into byts at 'packedBits'.  Going left to right,
+   Pack the bits of bitrow[] into bytes at 'packedBits'.  Going left to right,
    stop when there aren't enough bits left to fill a whole byte.  Return
    as *nextColP the number of the next column after the rightmost one we
    packed.
 
    Don't use any special CPU facilities to do the packing.
 -----------------------------------------------------------------------------*/
-    int col;
-
-    #define iszero(x) ((x) == 0 ? 0 : 1)
+    unsigned int col;
 
-    for (col = 0; col < cols-7; col += 8)
+    for (col = 0; col + 7 < cols; col += 8)
         packedBits[col/8] = (
-            iszero(bitrow[col+0]) << 7 |
-            iszero(bitrow[col+1]) << 6 |
-            iszero(bitrow[col+2]) << 5 |
-            iszero(bitrow[col+3]) << 4 |
-            iszero(bitrow[col+4]) << 3 |
-            iszero(bitrow[col+5]) << 2 |
-            iszero(bitrow[col+6]) << 1 |
-            iszero(bitrow[col+7]) << 0
+            bitValue(bitrow[col+0]) << 7 |
+            bitValue(bitrow[col+1]) << 6 |
+            bitValue(bitrow[col+2]) << 5 |
+            bitValue(bitrow[col+3]) << 4 |
+            bitValue(bitrow[col+4]) << 3 |
+            bitValue(bitrow[col+5]) << 2 |
+            bitValue(bitrow[col+6]) << 1 |
+            bitValue(bitrow[col+7]) << 0
             );
     *nextColP = col;
 }