Skip to content

Commit

Permalink
avoid i_push_errorf() and i_fatal() in a few more places
Browse files Browse the repository at this point in the history
  • Loading branch information
tonycoz committed Nov 24, 2012
1 parent 8b30e24 commit 8ebac85
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
22 changes: 11 additions & 11 deletions bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions datatypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
10 changes: 5 additions & 5 deletions filters.im
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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; p<num; p++) {
Expand All @@ -1044,7 +1044,7 @@ i_nearest_color_foo(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *i
curdist = 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");
}
if (curdist < mindist) {
mindist = curdist;
Expand Down Expand Up @@ -1189,7 +1189,7 @@ i_nearest_color(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *oval,
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; p<num; p++) {
Expand All @@ -1206,7 +1206,7 @@ i_nearest_color(i_img *im, int num, i_img_dim *xo, i_img_dim *yo, i_color *oval,
curdist = 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");
}
if (curdist < mindist) {
mindist = curdist;
Expand Down
6 changes: 4 additions & 2 deletions hlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ i_int_init_hlines(
size_t bytes = count_y * sizeof(i_int_hline_entry *);

if (bytes / count_y != sizeof(i_int_hline_entry *)) {
i_fatal(3, "integer overflow calculating memory allocation\n");
dIMCTX;
im_fatal(aIMCTX, 3, "integer overflow calculating memory allocation\n");
}

hlines->start_y = start_y;
Expand Down Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion img8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8ebac85

Please sign in to comment.