about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-23 00:34:00 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2023-09-23 00:34:00 +0000
commit9a675079290758a7f68e497146cc3688f1c3d364 (patch)
tree30e5a0f51a60a65b9ca31a994767c201fcaeb923 /lib
parentc014bbdd71993b0a8c401091953016e776228673 (diff)
downloadnetpbm-mirror-9a675079290758a7f68e497146cc3688f1c3d364.tar.gz
netpbm-mirror-9a675079290758a7f68e497146cc3688f1c3d364.tar.xz
netpbm-mirror-9a675079290758a7f68e497146cc3688f1c3d364.zip
Fix arithmetic overflow when bits per sample is > 16
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@4679 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib')
-rw-r--r--lib/libpm.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libpm.c b/lib/libpm.c
index 78d941fa..b27b47d5 100644
--- a/lib/libpm.c
+++ b/lib/libpm.c
@@ -442,12 +442,20 @@ pm_maxvaltobits(int const maxval) {
     assert(false);
 }
 
+
+
 int
-pm_bitstomaxval(int const bits) {
-    return ( 1 << bits ) - 1;
+pm_bitstomaxval(int const bitCt) {
+
+    if (bitCt > 16)
+        pm_error("Bits per sample %u too large.  16 is maximum acceptable",
+                 bitCt);
+
+    return (1 << bitCt) - 1;
 }
 
 
+
 unsigned int PURE_FN_ATTR
 pm_lcm(unsigned int const x,
        unsigned int const y,