gif

read/write GIFs
git clone git://bvnf.space/gm.git
Log | Files | Refs | README

commit 1a5017f69e05703dabe5a06e17450422f09c24bf
parent f30dbdf7867e888d08480a141af3b0572fd09084
Author: phoebos <ben@bvnf.space>
Date:   Wed,  1 Sep 2021 22:37:53 +0100

check after malloc(3)

Diffstat:
Mgif.c | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/gif.c b/gif.c @@ -116,6 +116,10 @@ int gif_decode(unsigned char *buf, size_t len){ struct Gif g = {0 }; g.gct = malloc(sizeof(struct Color_table)); + if (g.gct == NULL) { + perror("malloc"); + exit(FAIL_SYS); + } struct Image *img; int cur_block; enum { HEAD = 1, SPEC = 2, IMGE = 4 }; @@ -174,7 +178,15 @@ gif_decode(unsigned char *buf, size_t len){ if (cur_block != IMGE) { cur_block = IMGE; img = malloc(sizeof(struct Image)); + if (img == NULL) { + perror("malloc"); + exit(FAIL_SYS); + } img->lct = malloc(sizeof(struct Color_table)); + if (img->lct == NULL) { + perror("malloc"); + exit(FAIL_SYS); + } img->lct->len = g.gct->len; gif_decode_image(img, g.gct, buf); } @@ -213,6 +225,10 @@ main(int argc, char **argv){ unsigned char *buf; buf = (unsigned char *) malloc(BUF_SIZE); + if (buf == NULL) { + perror("malloc"); + exit(FAIL_SYS); + } /* read the whole file from fd into buf. */ ssize_t bytes;