X-Git-Url: http://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/e7aea0c6f323c6bbf364093305e60bb78999a23f..5057c6695cbe55f5d13e8e10a1e630c7ee00ea12:/src/image.c?ds=sidebyside diff --git a/src/image.c b/src/image.c index 4657208..f68f2da 100644 --- a/src/image.c +++ b/src/image.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "pack.h" @@ -280,6 +281,15 @@ static unsigned char **allocframebuffer(size_t width, size_t height) unsigned char **new, *tmp; size_t i; + if (height > SIZE_MAX / sizeof *new) { + lbx_error_raise(LBX_ENOMEM); + return NULL; + } + + /* Ensure that there is at least one row in the framebuffer. */ + if (height == 0 || width == 0) + width = height = 1; + tmp = calloc(height, width); if (!tmp) { lbx_error_raise(LBX_ENOMEM); @@ -413,9 +423,9 @@ lbx_img_loadpalette(void *f, const struct lbx_file_ops *fops, } palette[i] = (struct lbx_colour) { - .red = entry[1] << 2, - .green = entry[2] << 2, - .blue = entry[3] << 2, + .red = entry[1] & 0x3f, + .green = entry[2] & 0x3f, + .blue = entry[3] & 0x3f, .active = 1, }; } @@ -451,9 +461,9 @@ lbx_img_getpalette(struct lbx_image *pub, struct lbx_colour palette[static 256]) } palette[img->palstart + i] = (struct lbx_colour){ - .red = entry[1] << 2, - .green = entry[2] << 2, - .blue = entry[3] << 2, + .red = entry[1], + .green = entry[2], + .blue = entry[3], .active = 1, }; }