]> git.imager.perl.org - imager.git/blobdiff - bmp.c
avoid a possible sign-extension for offsets/sizes in SGI
[imager.git] / bmp.c
diff --git a/bmp.c b/bmp.c
index 0e8fe8e75c2ee9674106979f611612fcb5a3ca59..caf59b422ca766f9a8a27e2dbd93efb56c91d653 100644 (file)
--- a/bmp.c
+++ b/bmp.c
@@ -311,7 +311,7 @@ write_packed(io_glue *ig, char *format, ...) {
       buf[0] = i & 255;
       buf[1] = i / 256;
       if (i_io_write(ig, buf, 2) == -1)
-       return 0;
+       goto fail;
       break;
 
     case 'V':
@@ -320,14 +320,14 @@ write_packed(io_glue *ig, char *format, ...) {
       buf[2] = (i >> 16) & 0xFF;
       buf[3] = (i >> 24) & 0xFF;
       if (i_io_write(ig, buf, 4) == -1)
-       return 0;
+       goto fail;
       break;
 
     case 'C':
     case 'c':
       buf[0] = i & 0xFF;
       if (i_io_write(ig, buf, 1) == -1)
-       return 0;
+       goto fail;
       break;
 
     default:
@@ -341,6 +341,10 @@ write_packed(io_glue *ig, char *format, ...) {
   va_end(ap);
 
   return 1;
+
+ fail:
+  va_end(ap);
+  return 0;
 }
 
 /*
@@ -741,7 +745,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");