about summary refs log tree commit diff
path: root/lib/libpam.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-05-19 03:11:23 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2010-05-19 03:11:23 +0000
commit1f2aae5b55e42ed8fa247785ee896f750042a12d (patch)
treea7d161c3641fddd49471c622ee7a2eec3e02d99a /lib/libpam.c
parent60a0d64307394bad62684c32bbccf89552d15090 (diff)
downloadnetpbm-mirror-1f2aae5b55e42ed8fa247785ee896f750042a12d.tar.gz
netpbm-mirror-1f2aae5b55e42ed8fa247785ee896f750042a12d.tar.xz
netpbm-mirror-1f2aae5b55e42ed8fa247785ee896f750042a12d.zip
fix assertion on 64 bit
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1215 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpam.c')
-rw-r--r--lib/libpam.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/libpam.c b/lib/libpam.c
index 6e158dcd..3c5e5192 100644
--- a/lib/libpam.c
+++ b/lib/libpam.c
@@ -755,13 +755,26 @@ pnm_readpaminitrestaspnm(FILE * const fileP,
                 
 unsigned int
 pnm_bytespersample(sample const maxval) {
+/*----------------------------------------------------------------------------
+   Return the number of bytes per sample in the PAM raster of a PAM image
+   with maxval 'maxval'.  It's defined to be the minimum number of bytes
+   needed for that maxval, i.e. 1 for maxval < 256, 2 otherwise.
+-----------------------------------------------------------------------------*/
+
+    /* The PAM format requires maxval to be greater than zero and less than
+       1<<16, but since that is a largely arbitrary restriction, we don't want
+       to rely on it.
+    */
 
-    assert(sizeof(maxval) * 8 <= 32);
+    unsigned int i;
+    sample a;
 
-    if      (maxval >>  8 == 0) return 1;
-    else if (maxval >> 16 == 0) return 2;
-    else if (maxval >> 24 == 0) return 3;
-    else                        return 4;
+    for (i = 0, a = maxval; i < sizeof(maxval)/8; ++i) {
+        if (a == 0)
+            return i;
+        a >>= 8;
+    }
+    return 0;  /* silence compiler warning */
 }