# HG changeset patch # User Matti Hamalainen # Date 1493279445 -10800 # Node ID 0525128adebf4d0b70cde367a0a078ee59fd58ce # Parent aa15519676701c475a3e8d7e9f1793a32f78a4aa Check for malloc fail. diff -r aa1551967670 -r 0525128adebf bpgdec.c --- 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