aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imagemagick.c11
-rw-r--r--src/netpbm.c14
2 files changed, 16 insertions, 9 deletions
diff --git a/src/imagemagick.c b/src/imagemagick.c
index ada2f6e..a168e80 100644
--- a/src/imagemagick.c
+++ b/src/imagemagick.c
@@ -30,14 +30,17 @@ struct image *imagemagick_open(FILE *f){
argv[0] = "convert";
argv[1] = "-depth";
argv[2] = "255";
- asprintf(&argv[3], "fd:%i", origfd);
- asprintf(&argv[4], "ppm:fd:%i", tmpfd[1]);
+ if((asprintf(&argv[3], "fd:%i", origfd) < 0) || (asprintf(&argv[4], "ppm:fd:%i", tmpfd[1]) < 0)){
+ fprintf(stderr, "Out of memory");
+ exit(EXIT_FAILURE);
+ }
argv[5] = NULL;
#ifdef NDEBUG
/* STFU OMFG */
- freopen("/dev/null", "w", stdout);
- freopen("/dev/null", "w", stderr);
+ FILE *unused __attribute__((unused));
+ unused = freopen("/dev/null", "w", stdout);
+ unused = freopen("/dev/null", "w", stderr);
#endif
execvp(argv[0], argv);
diff --git a/src/netpbm.c b/src/netpbm.c
index f30dbbc..0f5eac2 100644
--- a/src/netpbm.c
+++ b/src/netpbm.c
@@ -41,14 +41,14 @@ struct image *netpbm_open(FILE *f){
b->format = format;
skipspace(f);
- fscanf(f, "%u", &b->img.bufwidth);
+ if(fscanf(f, "%u", &b->img.bufwidth) != 1) goto err;
skipspace(f);
- fscanf(f, "%u", &b->img.bufheight);
+ if(fscanf(f, "%u", &b->img.bufheight) != 1) goto err;
if(format == '1' || format == '4'){
b->maxval = 1;
}else{
skipspace(f);
- fscanf(f, "%u", &b->maxval);
+ if(fscanf(f, "%u", &b->maxval) != 1) goto err;
}
/* whitespace character */
@@ -58,12 +58,16 @@ struct image *netpbm_open(FILE *f){
b->img.fmt = &netpbm;
return (struct image *)b;
+
+err:
+ free(b);
+ return NULL;
}
static unsigned char readvali(struct netpbm_t *b){
skipspace(b->f);
int val;
- fscanf(b->f, "%i", &val);
+ int unused = fscanf(b->f, "%i", &val);
return val * 255 / b->maxval;
}
@@ -129,7 +133,7 @@ int netpbm_read(struct image *img){
}
}else if(b->format == '6'){
if(b->maxval == 255){
- fread(img->buf, 1, left * 3, f);
+ int unused = fread(img->buf, 1, left * 3, f);
}else{
while(left--){
img->buf[a++] = readvalb(b);