Mercurial > hg > forks > libbpg
changeset 21:0525128adebf
Check for malloc fail.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 27 Apr 2017 10:50:45 +0300 |
parents | aa1551967670 |
children | 69089d946a14 |
files | bpgdec.c |
diffstat | 1 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/bpgdec.c Thu Apr 27 10:46:16 2017 +0300 +++ b/bpgdec.c Thu Apr 27 10:50:45 2017 +0300 @@ -322,6 +322,11 @@ fseek(f, 0, SEEK_SET); buf = malloc(buf_len); + if (!buf) { + fprintf(stderr, "Could not allocate memory for buffer.\n"); + exit(1); + } + if (fread(buf, 1, buf_len, f) != buf_len) { fprintf(stderr, "Error while reading file\n"); exit(1); @@ -339,10 +344,7 @@ #ifdef USE_PNG p = strrchr(outfilename, '.'); - if (p) - p++; - - if (p && strcasecmp(p, "ppm") != 0) { + if (p && strcasecmp(p + 1, "ppm") != 0) { png_save(img, outfilename, bit_depth); } else #endif