diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-05-19 03:11:23 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2010-05-19 03:11:23 +0000 |
commit | 1f2aae5b55e42ed8fa247785ee896f750042a12d (patch) | |
tree | a7d161c3641fddd49471c622ee7a2eec3e02d99a | |
parent | 60a0d64307394bad62684c32bbccf89552d15090 (diff) | |
download | netpbm-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
-rw-r--r-- | doc/HISTORY | 2 | ||||
-rw-r--r-- | lib/libpam.c | 23 |
2 files changed, 19 insertions, 6 deletions
diff --git a/doc/HISTORY b/doc/HISTORY index 493b04a2..29c39ed1 100644 --- a/doc/HISTORY +++ b/doc/HISTORY @@ -25,7 +25,7 @@ not yet BJH Release 10.51.00 libnetpbm, various PBM programs: Use SSE insted of MMX. Thanks Prophet of the Way <afu@wta.att.ne.jp>. - libnetpbm: remove bogus assertion. + pnm_bytespersample(): fix bogus assertion on 64 bit system. pnmtops: fix bug: 12 bits per sample output when 8 would do. Introduced in 10.40. 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 */ } |