Merge pull request #1948 from heuripedes/master

Improve error handling in some image loading functions
This commit is contained in:
Twinaphex 2015-07-11 22:21:36 +02:00
commit 97d6b4e3fd
2 changed files with 15 additions and 5 deletions

View File

@ -100,7 +100,11 @@ static bool rpng_image_load_argb_shift(const char *path,
&out_img->pixels, &out_img->width, &out_img->height); &out_img->pixels, &out_img->width, &out_img->height);
if (!ret) if (!ret)
{
out_img->pixels = NULL;
out_img->width = out_img->height = 0;
return false; return false;
}
texture_image_color_convert(r_shift, g_shift, b_shift, texture_image_color_convert(r_shift, g_shift, b_shift,
a_shift, out_img); a_shift, out_img);

View File

@ -36,7 +36,7 @@ bool rtga_image_load_shift(uint8_t *buf,
if (buf[2] != 2) if (buf[2] != 2)
{ {
fprintf(stderr, "TGA image is not uncompressed RGB.\n"); fprintf(stderr, "TGA image is not uncompressed RGB.\n");
return false; goto error;
} }
memcpy(info, buf + 12, 6); memcpy(info, buf + 12, 6);
@ -55,7 +55,7 @@ bool rtga_image_load_shift(uint8_t *buf,
if (!out_img->pixels) if (!out_img->pixels)
{ {
fprintf(stderr, "Failed to allocate TGA pixels.\n"); fprintf(stderr, "Failed to allocate TGA pixels.\n");
return false; goto error;
} }
tmp = buf + 18; tmp = buf + 18;
@ -64,9 +64,7 @@ bool rtga_image_load_shift(uint8_t *buf,
if (bits != 32 && bits != 24) if (bits != 32 && bits != 24)
{ {
fprintf(stderr, "Bit depth of TGA image is wrong. Only 32-bit and 24-bit supported.\n"); fprintf(stderr, "Bit depth of TGA image is wrong. Only 32-bit and 24-bit supported.\n");
free(out_img->pixels); goto error;
out_img->pixels = NULL;
return false;
} }
if (bits == 32) if (bits == 32)
@ -87,4 +85,12 @@ bool rtga_image_load_shift(uint8_t *buf,
} }
return true; return true;
error:
if (out_img->pixels)
free(out_img->pixels);
out_img->pixels = NULL;
out_img->width = out_img->height = 0;
return false;
} }