stb_image: Fix two bugs found via VC++ /analyze

Also fixes issue #366.
This commit is contained in:
Fabian Giesen 2021-07-04 21:42:44 -07:00
parent e5fd7f6ce0
commit ab18d9b250

View File

@ -3821,6 +3821,10 @@ static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp
else else
decode_n = z->s->img_n; decode_n = z->s->img_n;
// nothing to do if no components requested; check this now to avoid
// accessing uninitialized coutput[0] later
if (decode_n <= 0) { stbi__cleanup_jpeg(z); return NULL; }
// resample and color-convert // resample and color-convert
{ {
int k; int k;
@ -6862,9 +6866,10 @@ static void *stbi__load_gif_main(stbi__context *s, int **delays, int *x, int *y,
} }
if (delays) { if (delays) {
*delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers ); int *new_delays = (int*) STBI_REALLOC_SIZED( *delays, delays_size, sizeof(int) * layers );
if (!*delays) if (!new_delays)
return stbi__load_gif_main_outofmem(&g, out, delays); return stbi__load_gif_main_outofmem(&g, out, delays);
*delays = new_delays;
delays_size = layers * sizeof(int); delays_size = layers * sizeof(int);
} }
} else { } else {