From 2f87f669f103cc3148d78e361ed275d5c474b8dd Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Sat, 18 Aug 2018 01:00:40 -0400 Subject: [PATCH] fix null dereference (but scan-build still warns with "Assigned value is garbage or undefined") --- libretro-common/formats/jpeg/rjpeg.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libretro-common/formats/jpeg/rjpeg.c b/libretro-common/formats/jpeg/rjpeg.c index 9ef95e4f08..65cb6c3966 100644 --- a/libretro-common/formats/jpeg/rjpeg.c +++ b/libretro-common/formats/jpeg/rjpeg.c @@ -2505,15 +2505,18 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, if (n >= 3) { uint8_t *y = coutput[0]; - if (z->s->img_n == 3) - z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); - else - for (i=0; i < z->s->img_x; ++i) - { - out[0] = out[1] = out[2] = y[i]; - out[3] = 255; /* not used if n==3 */ - out += n; - } + if (y) + { + if (z->s->img_n == 3) + z->YCbCr_to_RGB_kernel(out, y, coutput[1], coutput[2], z->s->img_x, n); + else + for (i=0; i < z->s->img_x; ++i) + { + out[0] = out[1] = out[2] = y[i]; + out[3] = 255; /* not used if n==3 */ + out += n; + } + } } else {