From 8ebac85f46199cb0e1ce01ae60a8db6894bf9fbb Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Mon, 13 Aug 2012 18:12:07 +1000 Subject: [PATCH] avoid i_push_errorf() and i_fatal() in a few more places --- bmp.c | 22 +++++++++++----------- datatypes.c | 5 +++-- filters.im | 10 +++++----- hlines.c | 6 ++++-- image.c | 6 +++--- img8.c | 2 +- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/bmp.c b/bmp.c index 10e463cf..0e8fe8e7 100644 --- a/bmp.c +++ b/bmp.c @@ -768,13 +768,13 @@ read_1bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used, if (!clr_used) clr_used = 2; if (clr_used < 0 || clr_used > 2) { - i_push_errorf(0, "out of range colors used (%d)", clr_used); + im_push_errorf(aIMCTX, 0, "out of range colors used (%d)", clr_used); return NULL; } base_offset = FILEHEAD_SIZE + INFOHEAD_SIZE + clr_used * 4; if (offbits < base_offset) { - i_push_errorf(0, "image data offset too small (%ld)", offbits); + im_push_errorf(aIMCTX, 0, "image data offset too small (%ld)", offbits); return NULL; } @@ -886,13 +886,13 @@ read_4bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used, clr_used = 16; if (clr_used > 16 || clr_used < 0) { - i_push_errorf(0, "out of range colors used (%d)", clr_used); + im_push_errorf(aIMCTX, 0, "out of range colors used (%d)", clr_used); return NULL; } base_offset = FILEHEAD_SIZE + INFOHEAD_SIZE + clr_used * 4; if (offbits < base_offset) { - i_push_errorf(0, "image data offset too small (%ld)", offbits); + im_push_errorf(aIMCTX, 0, "image data offset too small (%ld)", offbits); return NULL; } @@ -1069,7 +1069,7 @@ read_4bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used, else { /*if (compression == BI_RLE4) {*/ myfree(packed); myfree(line); - i_push_errorf(0, "unknown 4-bit BMP compression (%d)", compression); + im_push_errorf(aIMCTX, 0, "unknown 4-bit BMP compression (%d)", compression); i_img_destroy(im); return NULL; } @@ -1118,13 +1118,13 @@ read_8bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used, if (!clr_used) clr_used = 256; if (clr_used > 256 || clr_used < 0) { - i_push_errorf(0, "out of range colors used (%d)", clr_used); + im_push_errorf(aIMCTX, 0, "out of range colors used (%d)", clr_used); return NULL; } base_offset = FILEHEAD_SIZE + INFOHEAD_SIZE + clr_used * 4; if (offbits < base_offset) { - i_push_errorf(0, "image data offset too small (%ld)", offbits); + im_push_errorf(aIMCTX, 0, "image data offset too small (%ld)", offbits); return NULL; } @@ -1267,7 +1267,7 @@ read_8bit_bmp(io_glue *ig, int xsize, int ysize, int clr_used, } else { myfree(line); - i_push_errorf(0, "unknown 8-bit BMP compression (%d)", compression); + im_push_errorf(aIMCTX, 0, "unknown 8-bit BMP compression (%d)", compression); i_img_destroy(im); return NULL; } @@ -1387,7 +1387,7 @@ read_direct_bmp(io_glue *ig, int xsize, int ysize, int bit_count, return 0; } if (rmask == 0) { - i_push_errorf(0, "Zero mask for channel %d", i); + im_push_errorf(aIMCTX, 0, "Zero mask for channel %d", i); return NULL; } masks.masks[i] = rmask; @@ -1411,12 +1411,12 @@ read_direct_bmp(io_glue *ig, int xsize, int ysize, int bit_count, base_offset += 3 * 4; } else { - i_push_errorf(0, "unknown 24-bit BMP compression (%d)", compression); + im_push_errorf(aIMCTX, 0, "unknown 24-bit BMP compression (%d)", compression); return NULL; } if (offbits < base_offset) { - i_push_errorf(0, "image data offset too small (%ld)", offbits); + im_push_errorf(aIMCTX, 0, "image data offset too small (%ld)", offbits); return NULL; } diff --git a/datatypes.c b/datatypes.c index 3da4c5b0..c6604100 100644 --- a/datatypes.c +++ b/datatypes.c @@ -130,8 +130,9 @@ llist_push(struct llist *l,const void *data) { } } /* fprintf(stderr,"0x%08X\n",l->t); */ - if (llist_llink_push(l,l->t,data)) { - i_fatal(3, "out of memory\n"); + if (llist_llink_push(l,l->t,data)) { + dIMCTX; + im_fatal(aIMCTX, 3, "out of memory\n"); } } diff --git a/filters.im b/filters.im index 6f36a0fe..918963ec 100644 --- a/filters.im +++ b/filters.im @@ -972,7 +972,7 @@ i_gradgen(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *ival, int d fdist[p] = i_max(xd*xd, yd*yd); /* manhattan distance */ break; default: - i_fatal(3,"i_gradgen: Unknown distance measure\n"); + im_fatal(aIMCTX, 3,"i_gradgen: Unknown distance measure\n"); } cs += fdist[p]; } @@ -1027,7 +1027,7 @@ i_nearest_color_foo(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *i mindist = i_max(xd*xd, yd*yd); /* manhattan distance */ break; default: - i_fatal(3,"i_nearest_color: Unknown distance measure\n"); + im_fatal(aIMCTX, 3,"i_nearest_color: Unknown distance measure\n"); } for(p = 1; pstart_y = start_y; @@ -112,7 +113,8 @@ i_int_hlines_add(i_int_hlines *hlines, i_img_dim y, i_img_dim x, i_img_dim width i_img_dim x_limit = x + width; if (width < 0) { - i_fatal(3, "negative width %d passed to i_int_hlines_add\n", width); + dIMCTX; + im_fatal(aIMCTX, 3, "negative width %d passed to i_int_hlines_add\n", width); } /* just return if out of range */ diff --git a/image.c b/image.c index f44391c0..56057e87 100644 --- a/image.c +++ b/image.c @@ -117,7 +117,7 @@ ICL_new_internal(unsigned char r,unsigned char g,unsigned char b,unsigned char a im_log((aIMCTX,1,"ICL_new_internal(r %d,g %d,b %d,a %d)\n", r, g, b, a)); - if ( (cl=mymalloc(sizeof(i_color))) == NULL) i_fatal(2,"malloc() error\n"); + if ( (cl=mymalloc(sizeof(i_color))) == NULL) im_fatal(aIMCTX, 2,"malloc() error\n"); cl->rgba.r = r; cl->rgba.g = g; cl->rgba.b = b; @@ -147,7 +147,7 @@ ICL_set_internal(i_color *cl,unsigned char r,unsigned char g,unsigned char b,uns im_log((aIMCTX,1,"ICL_set_internal(cl* %p,r %d,g %d,b %d,a %d)\n",cl,r,g,b,a)); if (cl == NULL) if ( (cl=mymalloc(sizeof(i_color))) == NULL) - i_fatal(2,"malloc() error\n"); + im_fatal(aIMCTX, 2,"malloc() error\n"); cl->rgba.r=r; cl->rgba.g=g; cl->rgba.b=b; @@ -223,7 +223,7 @@ i_fcolor *i_fcolor_new(double r, double g, double b, double a) { im_log((aIMCTX, 1,"i_fcolor_new(r %g,g %g,b %g,a %g)\n", r, g, b, a)); - if ( (cl=mymalloc(sizeof(i_fcolor))) == NULL) i_fatal(2,"malloc() error\n"); + if ( (cl=mymalloc(sizeof(i_fcolor))) == NULL) im_fatal(aIMCTX, 2,"malloc() error\n"); cl->rgba.r = r; cl->rgba.g = g; cl->rgba.b = b; diff --git a/img8.c b/img8.c index 29e9700a..373d5a18 100644 --- a/img8.c +++ b/img8.c @@ -177,7 +177,7 @@ im_img_empty_ch(pIMCTX, i_img *im,i_img_dim x,i_img_dim y,int ch) { im->ch_mask = MAXINT; im->bytes=bytes; if ( (im->idata=mymalloc(im->bytes)) == NULL) - i_fatal(2,"malloc() error\n"); + im_fatal(aIMCTX, 2,"malloc() error\n"); memset(im->idata,0,(size_t)im->bytes); im->ext_data = NULL; -- 2.39.5