]> git.imager.perl.org - imager.git/commitdiff
avoid undefined behaviour adding integers
authorTony Cook <tony@develop-help.com>
Thu, 21 Feb 2013 03:37:20 +0000 (14:37 +1100)
committerTony Cook <tony@develop-help.com>
Thu, 21 Feb 2013 03:37:20 +0000 (14:37 +1100)
bmp.c
imdatatypes.h

diff --git a/bmp.c b/bmp.c
index 0e8fe8e75c2ee9674106979f611612fcb5a3ca59..61a7d82dfab6c67fad3c6f0eb90c8ab14a1c9878 100644 (file)
--- a/bmp.c
+++ b/bmp.c
@@ -741,7 +741,7 @@ read_1bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used,
     return NULL;
   }
 
-  if (xsize + 8 < xsize) { /* if there was overflow */
+  if ((i_img_dim)((i_img_dim_u)xsize + 8) < xsize) { /* if there was overflow */
     /* we check with 8 because we allocate that much for the decoded 
        line buffer */
     i_push_error(0, "integer overflow during memory allocation");
index a7419ea5bc93625356446cbcfb6e56bbac602142..1fa7c0b530b703f8d01f3d23a95690d80fccf5be 100644 (file)
@@ -41,6 +41,7 @@ May be larger than int on some platforms.
 */
 
 typedef ptrdiff_t i_img_dim;
+typedef size_t i_img_dim_u;
 
 /*
 =item i_color