Skip to content

Commit

Permalink
avoid undefined behaviour adding integers
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Feb 21, 2013
1 parent 5e84d11 commit 91fb86b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions imdatatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91fb86b

Please sign in to comment.