(libretro-common/formats/jpeg/rjpeg.c) Allocate out_img->pixels

This commit is contained in:
twinaphex 2016-05-07 06:49:48 +02:00
parent f86d4d400d
commit c5895b4aa0

View File

@ -1,3 +1,4 @@
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
@ -851,15 +852,26 @@ bool rjpeg_image_load(uint8_t *buf, void *data, size_t size)
if (!rjpg)
goto error;
out_img->pixels = (uint32_t*)buf;
out_img->width = rjpg->width;
out_img->height = rjpg->height;
out_img->pixels = (uint32_t*)malloc(rjpg->width * rjpg->height * rjpg->ncomp);
if (!out_img->pixels)
{
fprintf(stderr, "Failed to allocate JPEG pixels.\n");
goto error;
}
memcpy(out_img->pixels, rjpg->rgb, rjpg->width * rjpg->height * rjpg->ncomp);
rjpeg_free(rjpg);
return true;
error:
if (out_img->pixels)
free(out_img->pixels);
out_img->pixels = NULL;
out_img->width = out_img->height = 0;