Commit: 3d2bd12a188a721b56b53aa034bcb47f61678265
Parent: 47e5ff5777b31ca4e1c4f4bc9e5bc1f55f02afeb
Author: opask
Date: Thu, 19 Jul 2018 06:44:25 -0600
replace mem_alloc with xmalloc, update TODO
Diffstat:
42 files changed, 205 insertions(+), 199 deletions(-)
diff --git a/TODO b/TODO
@@ -35,3 +35,5 @@
- check if restrict is being used correctly
- its likely not even necessary
+
+- other error mechanisms should be replaced with die()
diff --git a/auth.c b/auth.c
@@ -31,7 +31,7 @@ unsigned char *base64_encode(unsigned char *in, int inlen, unsigned char *prefix
line_mask = (1 << line_bits) - 1;
data_len += (data_len + line_mask) >> line_bits;
}
- outstr = mem_alloc(prefix_len + data_len + suffix_len + 1);
+ outstr = xmalloc(prefix_len + data_len + suffix_len + 1);
memcpy(outstr, prefix, prefix_len);
out = outstr + prefix_len;
col = 0;
@@ -220,7 +220,7 @@ void add_auth(unsigned char *url, unsigned char *realm, unsigned char *user, uns
la = la->prev;
free_auth_entry(a);
}
- a = mem_alloc(sizeof(struct http_auth));
+ a = xmalloc(sizeof(struct http_auth));
a->host = host;
a->port = port;
a->realm = stracpy(realm);
diff --git a/bfu.c b/bfu.c
@@ -20,7 +20,7 @@ struct memory_list *getml(void *p, ...)
n++, q = va_arg(ap, void *);
}
if ((unsigned)n > (MAXINT - sizeof(struct memory_list)) / sizeof(void *)) overalloc();
- ml = mem_alloc(sizeof(struct memory_list) + n * sizeof(void *));
+ ml = xmalloc(sizeof(struct memory_list) + n * sizeof(void *));
ml->n = n;
n = 0;
q = p;
@@ -38,7 +38,7 @@ void add_to_ml(struct memory_list **ml, ...)
int n = 0;
void *q;
if (!*ml) {
- *ml = mem_alloc(sizeof(struct memory_list));
+ *ml = xmalloc(sizeof(struct memory_list));
(*ml)->n = 0;
}
va_start(ap, ml);
@@ -160,7 +160,7 @@ void do_menu_selected(struct terminal *term, struct menu_item *items, void *data
int i;
struct menu *menu;
for (i = 0; items[i].text; i++) if (i == (MAXINT - sizeof(struct menu)) / sizeof(unsigned)) overalloc();
- menu = mem_alloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned));
+ menu = xmalloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = selected;
menu->view = 0;
menu->ni = i;
@@ -617,7 +617,7 @@ void do_mainmenu(struct terminal *term, struct menu_item *items, void *data, int
int i;
struct mainmenu *menu;
for (i = 0; items[i].text; i++) if (i == (MAXINT - sizeof(struct mainmenu)) / sizeof(unsigned)) overalloc();
- menu = mem_alloc(sizeof(struct mainmenu) + (!i ? 0 : i - 1) * sizeof(unsigned));
+ menu = xmalloc(sizeof(struct mainmenu) + (!i ? 0 : i - 1) * sizeof(unsigned));
menu->selected = sel == -1 ? 0 : sel;
menu->ni = i;
menu->items = items;
@@ -872,7 +872,7 @@ void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int
}
}
if (di->item->type == D_FIELD_PASS) {
- t = mem_alloc(vposlen + 1);
+ t = xmalloc(vposlen + 1);
memset(t, '*', vposlen);
t[vposlen] = 0;
} else {
@@ -996,7 +996,7 @@ void display_dlg_item(struct dialog_data *dlg, struct dialog_item_data *di, int
case D_BUTTON:
st = sel ? bfu_style_wb_b : bfu_style_bw;
text = get_text_translation(di->item->text, term);
- text2 = mem_alloc(strlen(cast_const_char text) + 5);
+ text2 = xmalloc(strlen(cast_const_char text) + 5);
strcpy(cast_char text2, cast_const_char G_DIALOG_BUTTON_L);
strcpy(cast_char(text2 + 2), cast_const_char text);
strcat(cast_char text2, cast_const_char G_DIALOG_BUTTON_R);
@@ -1251,7 +1251,7 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
struct dialog_item_data * highc_volatile di = &dlg->items[i];
memset(di, 0, sizeof(struct dialog_item_data));
di->item = &dlg->dlg->items[i];
- di->cdata = mem_alloc(di->item->dlen);
+ di->cdata = xmalloc(di->item->dlen);
if (di->item->dlen)
memcpy(di->cdata, di->item->data, di->item->dlen);
if (di->item->type == D_CHECKBOX) {
@@ -1269,7 +1269,7 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd)
struct history_item *hi;
size_t sl = strlen(cast_const_char j->str);
if (sl > MAXINT - sizeof(struct history_item)) overalloc();
- hi = mem_alloc(sizeof(struct history_item) + sl);
+ hi = xmalloc(sizeof(struct history_item) + sl);
strcpy(cast_char hi->str, cast_const_char j->str);
add_to_list(di->history, hi);
}
@@ -2282,7 +2282,7 @@ void add_to_history(struct terminal *term, struct history *h, unsigned char *t)
}
l = strlen(cast_const_char s);
if (l > MAXINT - sizeof(struct history_item)) overalloc();
- hi = mem_alloc(sizeof(struct history_item) + l);
+ hi = xmalloc(sizeof(struct history_item) + l);
memcpy(hi->str, s, l + 1);
if (term)
mem_free(s);
diff --git a/block.c b/block.c
@@ -45,7 +45,7 @@ static struct list *block_new_item(void *ignore)
/*Default constructor*/
struct block *neww;
- neww = mem_alloc(sizeof(struct block));
+ neww = xmalloc(sizeof(struct block));
neww->url = stracpy(cast_uchar "");
return &neww->head;
}
@@ -172,7 +172,7 @@ static void block_edit_item(struct dialog_data *dlg, struct list *data, void (*o
unsigned char *url, *txt;
/*Allocate space for dialog, 4 items followed by 1 string*/
- d = mem_alloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + 1 * MAX_STR_LEN);
+ d = xmalloc(sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + 1 * MAX_STR_LEN);
memset(d, 0, sizeof(struct dialog) + 4 * sizeof(struct dialog_item) + 1 * MAX_STR_LEN);
/*Set up this string */
@@ -182,7 +182,7 @@ static void block_edit_item(struct dialog_data *dlg, struct list *data, void (*o
mem_free(txt);
/* Create the dialog */
- s = mem_alloc(sizeof(struct assoc_ok_struct));
+ s = xmalloc(sizeof(struct assoc_ok_struct));
s->fn = ok_fn;
s->data = ok_arg;
diff --git a/bookmark.c b/bookmark.c
@@ -114,9 +114,9 @@ static void *bookmark_default_value(struct session *ses, unsigned char type)
struct kawasaki *zelena;
unsigned char *txt;
- txt=mem_alloc(MAX_STR_LEN);
+ txt = xmalloc(MAX_STR_LEN);
- zelena=mem_alloc(sizeof(struct kawasaki));
+ zelena = xmalloc(sizeof(struct kawasaki));
zelena->url=NULL;
zelena->title=NULL;
@@ -256,7 +256,7 @@ static void bookmark_edit_item(struct dialog_data *dlg, struct list *data, void
int a;
/* Create the dialog */
- s = mem_alloc(sizeof(struct bookmark_ok_struct));
+ s = xmalloc(sizeof(struct bookmark_ok_struct));
s->fn = ok_fn;
s->data = ok_arg;
s->dlg = dlg;
@@ -342,7 +342,7 @@ static struct list *bookmark_new_item(void *data)
struct bookmark_list *b;
struct kawasaki *zelena = (struct kawasaki *)data;
- b = mem_alloc(sizeof(struct bookmark_list));
+ b = xmalloc(sizeof(struct bookmark_list));
if (zelena && zelena->title)
b->title = zelena->title;
@@ -479,7 +479,7 @@ static void add_bookmark(unsigned char *title, unsigned char *url, int depth)
if (!title) return;
- b = mem_alloc(sizeof(struct bookmark_list));
+ b = xmalloc(sizeof(struct bookmark_list));
dop = mem_calloc(sizeof(struct document_options));
dop->cp = bookmark_ld.codepage;
diff --git a/cache.c b/cache.c
@@ -269,7 +269,7 @@ have_f:
/*if (C_ALIGN(length) > MAXINT - sizeof(struct fragment) || C_ALIGN(length) < 0) overalloc();*/
ca = C_ALIGN(length);
if (ca > MAXINT - (int)sizeof(struct fragment) || ca < 0) return S_LARGE_FILE;
- nf = mem_alloc_mayfail(sizeof(struct fragment) + (size_t)ca);
+ nf = xmalloc(sizeof(struct fragment) + (size_t)ca);
if (!nf) return S_OUT_OF_MEM;
sf(length);
nf->offset = offset;
@@ -337,7 +337,7 @@ int defrag_entry(struct cache_entry *e)
l += list_struct(h, struct fragment)->length;
}
if (l > MAXINT - (int)sizeof(struct fragment)) return S_LARGE_FILE;
- n = mem_alloc_mayfail(sizeof(struct fragment) + (size_t)l);
+ n = xmalloc(sizeof(struct fragment) + (size_t)l);
if (!n) return S_OUT_OF_MEM;
n->offset = 0;
n->length = l;
diff --git a/charsets.c b/charsets.c
@@ -168,7 +168,7 @@ static void add_utf_8(struct conv_table *ct, int u, unsigned char *str)
internal("bad utf encoding #1");
return;
}
- nct = mem_alloc(sizeof(struct conv_table) * 256);
+ nct = xmalloc(sizeof(struct conv_table) * 256);
memset(nct, 0, sizeof(struct conv_table) * 256);
new_translation_table(nct);
ct[*p].t = 1;
@@ -381,7 +381,7 @@ unsigned char *convert_string(struct conv_table *ct, unsigned char *c, int l, st
return memacpy(c, l);
xx:;
}
- buffer = mem_alloc(ALLOC_GR);
+ buffer = xmalloc(ALLOC_GR);
while (pp < l) {
unsigned char *e = NULL; /* against warning */
if (c[pp] < 128 && c[pp] != '&') {
diff --git a/compress.c b/compress.c
@@ -20,7 +20,7 @@ static void decoder_memory_init(unsigned char **p, size_t *size, off_t init_leng
{
if (init_length > 0 && init_length < MAXINT) *size = (int)init_length;
else *size = 4096;
- *p = mem_alloc(*size);
+ *p = xmalloc(*size);
}
static int decoder_memory_expand(unsigned char **p, size_t size, size_t *addsize)
diff --git a/connect.c b/connect.c
@@ -920,7 +920,7 @@ void write_to_socket(struct connection *c, int s, unsigned char *data, int len,
struct write_buffer *wb;
log_data(data, len);
if ((unsigned)len > MAXINT - sizeof(struct write_buffer)) overalloc();
- wb = mem_alloc(sizeof(struct write_buffer) + len);
+ wb = xmalloc(sizeof(struct write_buffer) + len);
wb->sock = s;
wb->len = len;
wb->pos = 0;
@@ -1008,7 +1008,7 @@ success:
struct read_buffer *alloc_read_buffer(struct connection *c)
{
struct read_buffer *rb;
- rb = mem_alloc(sizeof(struct read_buffer) + READ_SIZE);
+ rb = xmalloc(sizeof(struct read_buffer) + READ_SIZE);
memset(rb, 0, sizeof(struct read_buffer));
return rb;
}
diff --git a/cookies.c b/cookies.c
@@ -55,7 +55,7 @@ int set_cookie(struct terminal *term, unsigned char *url, unsigned char *str)
break;
}
if (str == q || q + 1 == p) return 0;
- cookie = mem_alloc(sizeof(struct cookie));
+ cookie = xmalloc(sizeof(struct cookie));
server = get_host_name(url);
cookie->name = memacpy(str, q - str);
cookie->value = !noval ? memacpy(q + 1, p - q - 1) : NULL;
@@ -135,7 +135,7 @@ static void accept_cookie(struct cookie *c)
foreach(struct c_domain, cd, lcd, c_domains) if (!casestrcmp(cd->domain, c->domain)) return;
sl = strlen(cast_const_char c->domain);
if (sl > MAXINT - sizeof(struct c_domain)) overalloc();
- cd = mem_alloc(sizeof(struct c_domain) + sl);
+ cd = xmalloc(sizeof(struct c_domain) + sl);
strcpy(cast_char cd->domain, cast_const_char c->domain);
add_to_list(c_domains, cd);
}
diff --git a/default.c b/default.c
@@ -1231,7 +1231,7 @@ static unsigned char *x_proxy_cmd(struct option *o, unsigned char ***argv, int *
unsigned char **pass_argv;
unsigned char *result, *ret;
if (!*argc) return cast_uchar "Parameter expected";
- result = mem_alloc(MAX_STR_LEN);
+ result = xmalloc(MAX_STR_LEN);
if (save(get_commandline_charset(), result, **argv)) {
mem_free(result);
return err;
diff --git a/dip.c b/dip.c
@@ -278,7 +278,7 @@ static void enlarge_gray_horizontal(unsigned char *in, int ix, int y,
if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc();
if ((unsigned)ox * (unsigned)y > MAXINT) overalloc();
- outptr=mem_alloc(ox*y);
+ outptr = xmalloc(ox * y);
inptr=in;
*out=outptr;
if (ix==1){
@@ -292,7 +292,7 @@ static void enlarge_gray_horizontal(unsigned char *in, int ix, int y,
}else{
total=(ix-1)*(ox-1);
if ((unsigned)y > MAXINT / sizeof(*col_buf)) overalloc();
- col_buf=mem_alloc(y*sizeof(*col_buf));
+ col_buf = xmalloc(y * sizeof(*col_buf));
bias_buf_gray(col_buf, y, half);
out_pos=0;
in_pos=0;
@@ -351,7 +351,7 @@ static void enlarge_color_horizontal(unsigned short *in, int ix, int y,
}
if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc();
if ((unsigned)ox * (unsigned)y > MAXINT / 3 / sizeof(*out)) overalloc();
- out=mem_alloc_mayfail(sizeof(*out)*3*ox*y);
+ out = xmalloc(sizeof(*out) * 3 * ox * y);
*outa=out;
if (!out) {
mem_free(in);
@@ -374,7 +374,7 @@ static void enlarge_color_horizontal(unsigned short *in, int ix, int y,
alloc_size = (int)(y*3*sizeof(*col_buf));
alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1);
if (alloc_size > MAXINT / n_threads) overalloc();
- col_buf = mem_alloc_mayfail(alloc_size * n_threads);
+ col_buf = xmalloc(alloc_size * n_threads);
if (!col_buf) goto skip_omp;
{
scale_t *thread_col_buf;
@@ -430,11 +430,11 @@ static void scale_gray_horizontal(unsigned char *in, int ix, int y,
}
if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc();
if ((unsigned)ox * (unsigned)y > MAXINT) overalloc();
- outptr=mem_alloc(ox*y);
+ outptr = xmalloc(ox * y);
inptr=in;
*out=outptr;
if ((unsigned)y > MAXINT / sizeof(*col_buf)) overalloc();
- col_buf=mem_alloc(y*sizeof(*col_buf));
+ col_buf = xmalloc(y * sizeof(*col_buf));
bias_buf_gray(col_buf, y, ix>>1);
out_pos=0;
in_pos=0;
@@ -494,7 +494,7 @@ static void scale_color_horizontal(unsigned short *in, int ix, int y,
multiply_int(ix,ox);
if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc();
if ((unsigned)ox * (unsigned)y > MAXINT / 3 / sizeof(*out)) overalloc();
- out=mem_alloc_mayfail(sizeof(*out)*3*ox*y);
+ out = xmalloc(sizeof(*out) * 3 * ox * y);
*outa=out;
if (!out) {
mem_free(in);
@@ -506,7 +506,7 @@ static void scale_color_horizontal(unsigned short *in, int ix, int y,
alloc_size = (int)(y*3*sizeof(*col_buf));
alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1);
if (alloc_size > MAXINT / n_threads) overalloc();
- col_buf = mem_alloc_mayfail(alloc_size * n_threads);
+ col_buf = xmalloc(alloc_size * n_threads);
if (!col_buf) goto skip_omp;
{
scale_t *thread_col_buf;
@@ -559,7 +559,7 @@ static void enlarge_gray_vertical(unsigned char *in, int x, int iy,
if (iy==1){
if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc();
if ((unsigned)x * (unsigned)oy > MAXINT) overalloc();
- outptr=mem_alloc(oy*x);
+ outptr = xmalloc(oy * x);
*out=outptr;
for(;oy;oy--,outptr+=x)
memcpy(outptr,in,x);
@@ -570,12 +570,12 @@ static void enlarge_gray_vertical(unsigned char *in, int x, int iy,
}else{
if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc();
if ((unsigned)x * (unsigned)oy > MAXINT) overalloc();
- outptr=mem_alloc(oy*x);
+ outptr = xmalloc(oy*x);
inptr=in;
*out=outptr;
total=(iy-1)*(oy-1);
if ((unsigned)x > MAXINT / sizeof(*row_buf)) overalloc();
- row_buf=mem_alloc(x*sizeof(*row_buf));
+ row_buf = xmalloc(x * sizeof(*row_buf));
bias_buf_gray(row_buf, x, half);
out_pos=0;
in_pos=0;
@@ -622,7 +622,7 @@ static void enlarge_color_vertical(unsigned short *in, int x, int iy,
/* Rivendell */
if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc();
if ((unsigned)x * (unsigned)oy > MAXINT / 3 / sizeof(*out)) overalloc();
- out=mem_alloc_mayfail(sizeof(*out)*3*oy*x);
+ out = xmalloc(sizeof(*out) * 3 * oy * x);
*outa=out;
if (!out) {
mem_free(in);
@@ -643,7 +643,7 @@ static void enlarge_color_vertical(unsigned short *in, int x, int iy,
alloc_size = (int)(x*3*sizeof(*row_buf));
alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1);
if (alloc_size > MAXINT / n_threads) overalloc();
- row_buf = mem_alloc_mayfail(alloc_size * n_threads);
+ row_buf = xmalloc(alloc_size * n_threads);
if (!row_buf) goto skip_omp;
{
scale_t *thread_row_buf;
@@ -701,7 +701,7 @@ static void scale_gray_vertical(unsigned char *in, int x, int iy,
}
if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc();
if ((unsigned)x * (unsigned)oy > MAXINT) overalloc();
- outptr=mem_alloc(x*oy);
+ outptr = xmalloc(x * oy);
inptr=in;
*out=outptr;
if ((unsigned)x > MAXINT / sizeof(*row_buf)) overalloc();
@@ -763,7 +763,7 @@ static void scale_color_vertical(unsigned short *in, int x, int iy,
multiply_int(iy,oy);
if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc();
if ((unsigned)x * (unsigned)oy > MAXINT / 3 / sizeof(*out)) overalloc();
- out=mem_alloc_mayfail(sizeof(*out)*3*oy*x);
+ out = xmalloc(sizeof(*out) * 3 * oy * x);
*outa=out;
if (!out) {
mem_free(in);
@@ -774,7 +774,7 @@ static void scale_color_vertical(unsigned short *in, int x, int iy,
alloc_size = (int)(x*3*sizeof(*row_buf));
alloc_size = (alloc_size + SMP_ALIGN - 1) & ~(SMP_ALIGN - 1);
if (alloc_size > MAXINT / n_threads) overalloc();
- row_buf = mem_alloc_mayfail(alloc_size * n_threads);
+ row_buf = xmalloc(alloc_size * n_threads);
if (!row_buf) goto skip_omp;
{
scale_t *thread_row_buf;
@@ -1289,7 +1289,7 @@ void make_gamma_table(struct cached_image *cimg)
if (cimg->buffer_bytes_per_pixel<=4){
/* 8-bit */
- ptr_16=mem_alloc(768*sizeof(*(cimg->gamma_table)));
+ ptr_16 = xmalloc(768 * sizeof(*(cimg->gamma_table)));
cimg->gamma_table=ptr_16;
for (a=0;a<256;a++,ptr_16++){
last_val = (unsigned short)(65535*fd_pow((float_double)a*inv_255,rg)+(float_double)0.5);
@@ -1314,7 +1314,7 @@ void make_gamma_table(struct cached_image *cimg)
last_val = 0; /* against warning */
/* 16-bit */
- ptr_16=mem_alloc(196608*sizeof(*(cimg->gamma_table)));
+ ptr_16 = xmalloc(196608 * sizeof(*(cimg->gamma_table)));
cimg->gamma_table=ptr_16;
for (a=0;a<0x10000;a++,ptr_16++){
if (!x_slow_fpu || !(a & 0xff)) {
@@ -1489,7 +1489,7 @@ static void load_metric(int *x, int *y, int char_number, int *style_table)
#ifdef PNG_USER_MEM_SUPPORTED
void *my_png_alloc(png_structp png_ptr, png_size_t size)
{
- void *ptr = mem_alloc_mayfail(size);
+ void *ptr = xmalloc(size);
return ptr;
}
void my_png_free(png_structp png_ptr, void *ptr)
@@ -1584,9 +1584,9 @@ const unsigned char *png_data, int png_length)
png_read_update_info(png_ptr,info_ptr);
if (*x && (unsigned)*x * (unsigned)*y / (unsigned)*x != (unsigned)*y) overalloc();
if ((unsigned)*x * (unsigned)*y > MAXINT) overalloc();
- *dest=mem_alloc(*x*(*y));
+ *dest = xmalloc(*x * (*y));
if ((unsigned)*y > MAXINT / sizeof(*ptrs)) overalloc();
- ptrs=mem_alloc(*y*sizeof(*ptrs));
+ ptrs = xmalloc(*y * sizeof(*ptrs));
for (y1=0;y1<*y;y1++) ptrs[y1]=*dest+*x*y1;
for (;number_of_passes;number_of_passes--){
png_read_rows(png_ptr, ptrs, NULL, *y);
@@ -1620,7 +1620,7 @@ const unsigned char *png_data, int png_length, struct style *style)
iy=y+2;
if (ix && (unsigned)ix * (unsigned)iy / (unsigned)ix != (unsigned)iy) overalloc();
if ((unsigned)ix * (unsigned)iy > MAXINT) overalloc();
- interm2=mem_alloc(ix*iy);
+ interm2 = xmalloc(ix * iy);
i2ptr=interm2+ix+1;
dptr=*dest;
memset(interm2,0,ix);
@@ -1668,13 +1668,13 @@ ATTR_NOINLINE static struct font_cache_entry *supply_color_cache_entry(struct st
unsigned short red, green, blue;
unsigned bytes_consumed;
- found=mem_alloc(sizeof(*found));
+ found = xmalloc(sizeof(*found));
found->bitmap.y=style->height;
load_scaled_char(&(found->bitmap.data),&(found->bitmap.x),
found->bitmap.y, letter->begin,
letter->length, style);
- neww=mem_alloc(sizeof(*neww));
+ neww = xmalloc(sizeof(*neww));
locked_color_entry = neww;
neww->bitmap=found->bitmap;
neww->r0=style->r0;
@@ -1688,8 +1688,7 @@ ATTR_NOINLINE static struct font_cache_entry *supply_color_cache_entry(struct st
if (neww->bitmap.x && (unsigned)neww->bitmap.x * (unsigned)neww->bitmap.y / (unsigned)neww->bitmap.x != (unsigned)neww->bitmap.y) overalloc();
if ((unsigned)neww->bitmap.x * (unsigned)neww->bitmap.y > MAXINT / 3 / sizeof(*primary_data)) overalloc();
- primary_data=mem_alloc(3
- *neww->bitmap.x*neww->bitmap.y*sizeof(*primary_data));
+ primary_data = xmalloc(3 * neww->bitmap.x * neww->bitmap.y * sizeof(*primary_data));
/* We assume the gamma of HTML styles is in sRGB space */
round_color_sRGB_to_48(&red, &green, &blue,
@@ -2150,7 +2149,7 @@ struct style *g_invert_style(struct style *old)
int length;
struct style *st;
- st = mem_alloc(sizeof(struct style));
+ st = xmalloc(sizeof(struct style));
st->refcount=1;
st->r0=old->r1;
st->g0=old->g1;
@@ -2168,7 +2167,7 @@ struct style *g_invert_style(struct style *old)
}
if ((unsigned)n_fonts > MAXINT / sizeof(*st->table)) overalloc();
length=(int)sizeof(*st->table)*(n_fonts-1);
- st->table=mem_alloc(length);
+ st->table = xmalloc(length);
memcpy(st->table,old->table,length);
st->mono_space=old->mono_space;
st->mono_height=old->mono_height;
@@ -2197,7 +2196,7 @@ struct style *g_get_style(int fg, int bg, int size, unsigned char *font, int fla
bg = hack_rgb(bg);
- st = mem_alloc(sizeof(struct style));
+ st = xmalloc(sizeof(struct style));
/* strcpy(st->font, font); */
st->refcount = 1;
st->r0 = bg >> 16;
@@ -2215,7 +2214,7 @@ struct style *g_get_style(int fg, int bg, int size, unsigned char *font, int fla
st->underline_color=dip_get_color_sRGB(fg);
}
if ((unsigned)n_fonts > MAXINT / sizeof(*st->table)) overalloc();
- st->table=mem_alloc(sizeof(*st->table)*(n_fonts-1));
+ st->table = xmalloc(sizeof(*st->table)*(n_fonts-1));
if(fill_style_table(st->table, font))
load_metric(&(st->mono_space), &(st->mono_height),' ',st->table);
else
@@ -2263,8 +2262,6 @@ long real_dip_get_color_sRGB(int rgb)
#include "links_ic.inc"
-/* ATTENTION!!! allocates using malloc. Due to braindead Xlib, which
- * frees it using free and thus it is not possible to use mem_alloc. */
void get_links_icon(unsigned char **data, int *width, int *height, int *skip, int pad)
{
struct bitmap b;
@@ -2279,11 +2276,8 @@ void get_links_icon(unsigned char **data, int *width, int *height, int *skip, in
while (b.skip % pad) b.skip++;
*skip=b.skip;
retry:
- if (!(b.data=*data=malloc(b.skip*b.y))) {
- out_of_memory(0, cast_uchar "icon malloc", b.skip*b.y);
- goto retry;
- }
- tmp1=mem_alloc(6*b.y*b.x);
+ b.data = *data = xmalloc(b.skip * b.y);
+ tmp1 = xmalloc(6 * b.y * b.x);
agx_24_to_48(tmp1,links_icon,b.x*b.y,g,g,g);
dither(tmp1, &b);
mem_free(tmp1);
diff --git a/dither.c b/dither.c
@@ -833,9 +833,9 @@ static void compress_tables(void)
return;
}
table_16 = 0;
- rt = mem_alloc(256 * sizeof(*rt));
- gt = mem_alloc(256 * sizeof(*gt));
- bt = mem_alloc(256 * sizeof(*bt));
+ rt = xmalloc(256 * sizeof(*rt));
+ gt = xmalloc(256 * sizeof(*gt));
+ bt = xmalloc(256 * sizeof(*bt));
for (i = 0; i < 256; i++) {
rt[i] = red_table[i << 8];
gt[i] = green_table[i << 8];
diff --git a/dns.c b/dns.c
@@ -376,7 +376,7 @@ static void end_dns_lookup(struct dnsquery *q, int a)
check_dns_cache_addr_preference();
sl = strlen(cast_const_char q->name);
if (sl > MAXINT - sizeof(struct dnsentry)) overalloc();
- dnsentry = mem_alloc(sizeof(struct dnsentry) + sl);
+ dnsentry = xmalloc(sizeof(struct dnsentry) + sl);
strcpy(cast_char dnsentry->name, cast_const_char q->name);
memcpy(&dnsentry->addr, q->addr, sizeof(struct lookup_result));
dnsentry->absolute_time = get_absolute_time();
diff --git a/error.c b/error.c
@@ -107,20 +107,6 @@ void debug_msg(char *m, ...)
va_end(l);
}
-void *mem_alloc_(size_t size, int mayfail)
-{
- void *p;
- dos_poll_break();
- debug_test_free(NULL, 0);
- if (!size) return DUMMY;
- retry:
- if (!(p = heap_malloc(size))) {
- if (out_of_memory_fl(0, !mayfail ? cast_uchar "malloc" : NULL, size, NULL, 0)) goto retry;
- return NULL;
- }
- return p;
-}
-
void *mem_calloc_(size_t size, int mayfail)
{
void *p;
@@ -149,7 +135,7 @@ void mem_free(void *p)
void *mem_realloc_(void *p, size_t size, int mayfail)
{
void *np;
- if (p == DUMMY) return mem_alloc_(size, mayfail);
+ if (p == DUMMY) return xmalloc(size);
dos_poll_break();
debug_test_free(NULL, 0);
if (!p) {
@@ -172,7 +158,7 @@ unsigned char *memacpy(const unsigned char *src, size_t len)
{
unsigned char *m;
if (!(len + 1)) overalloc();
- m = (unsigned char *)mem_alloc(len + 1);
+ m = xmalloc(len + 1);
if (len)
memcpy(m, src, len);
m[len] = 0;
diff --git a/file.c b/file.c
@@ -362,7 +362,7 @@ void file_func(struct connection *c)
if (buf) mem_free(buf);
size += ALLOC_GR;
if ((unsigned)size > MAXINT) overalloc();
- buf = mem_alloc(size);
+ buf = xmalloc(size);
EINTRLOOP(r, (int)readlink(cast_const_char n, cast_char buf, size));
} while (r == size);
if (r == -1) goto yyy;
@@ -420,7 +420,7 @@ void file_func(struct connection *c)
}
/* + !stt.st_size is there because of bug in Linux. Read returns
-EACCES when reading 0 bytes to invalid address */
- file = mem_alloc_mayfail((size_t)stt.st_size + !stt.st_size);
+ file = xmalloc((size_t)stt.st_size + !stt.st_size);
if (!file) {
EINTRLOOP(rs, close(h));
setcstate(c, S_OUT_OF_MEM);
diff --git a/gif.c b/gif.c
@@ -67,7 +67,7 @@ static void alloc_color_map(int colors)
if (deco->color_map) mem_free(deco->color_map);
if ((unsigned)colors > MAXINT / 3 / sizeof(*(deco->color_map))) overalloc();
- deco->color_map=mem_alloc(colors*3*sizeof(*(deco->color_map)));
+ deco->color_map = xmalloc(colors * 3 * sizeof(*(deco->color_map)));
}
/*
@@ -445,7 +445,7 @@ gif_accept_byte(unsigned char c)
if (global_cimg->width && (unsigned)global_cimg->width * (unsigned)global_cimg->buffer_bytes_per_pixel / (unsigned)global_cimg->width != (unsigned)global_cimg->buffer_bytes_per_pixel) overalloc();
if ((unsigned)global_cimg->width * (unsigned)global_cimg->buffer_bytes_per_pixel > MAXINT) overalloc();
deco->actual_line=global_cimg->strip_optimized
- ?mem_alloc((size_t)global_cimg->width*global_cimg
+ ?xmalloc((size_t)global_cimg->width * global_cimg
->buffer_bytes_per_pixel)
:global_cimg->buffer;
if (deco->tbuf[8]&128){
diff --git a/html.c b/html.c
@@ -575,7 +575,7 @@ void html_stack_dup(void)
struct html_element *ep;
html_format_changed = 1;
ep = &html_top;
- e = mem_alloc(sizeof(struct html_element));
+ e = xmalloc(sizeof(struct html_element));
memcpy(e, ep, sizeof(struct html_element));
e->attr.fontface = stracpy(ep->attr.fontface);
e->attr.link = stracpy(ep->attr.link);
@@ -2494,7 +2494,7 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int
for (i = 0; i < ol; i++) if (o[i] < 0) nn = 1;
if (!nn) goto distribute;
if ((unsigned)ol > MAXINT / sizeof(int)) overalloc();
- oo = mem_alloc(ol * sizeof(int));
+ oo = xmalloc(ol * sizeof(int));
memcpy(oo, o, ol * sizeof(int));
for (i = 0; i < ol; i++) if (o[i] < 1) o[i] = 1;
q = ww - q;
@@ -2568,7 +2568,7 @@ static void html_frameset(unsigned char *a)
horiz = 1;
if (!(c = get_attr_val(a, cast_uchar "rows"))) return;
}
- fp = mem_alloc(sizeof(struct frameset_param));
+ fp = xmalloc(sizeof(struct frameset_param));
fp->n = 0;
fp->horiz = horiz;
par_format.leftmargin = par_format.rightmargin = 0;
diff --git a/html_gr.c b/html_gr.c
@@ -32,7 +32,7 @@ struct background *get_background(unsigned char *bg, unsigned char *bgcolor)
{
struct background *b;
struct rgb r;
- b = mem_alloc(sizeof(struct background));
+ b = xmalloc(sizeof(struct background));
{
if (bgcolor && !decode_color(bgcolor, &r)) {
b->u.sRGB=(r.r << 16) + (r.g << 8) + r.b;
@@ -503,7 +503,7 @@ static void do_image(struct g_part *p, struct image_description *im)
if (get_file(af->rq, &start, &end)) goto ft;
if (start == end) goto ft;
if (get_image_map(ce->head, start, end, tag, &menu, &ml, format_.href_base, format_.target_base, 0, 0, 0, 1)) goto ft;
- map = mem_alloc(sizeof(struct image_map));
+ map = xmalloc(sizeof(struct image_map));
map->n_areas = 0;
for (i = 0; menu[i].text; i++) {
struct link_def *ld = menu[i].data;
diff --git a/html_r.c b/html_r.c
@@ -64,7 +64,7 @@ struct frameset_desc *copy_frameset_desc(struct frameset_desc *fd)
int i;
struct frameset_desc *neww;
if ((unsigned)fd->n > MAXINT / sizeof(struct frame_desc)) overalloc();
- neww = mem_alloc(sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc));
+ neww = xmalloc(sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc));
memcpy(neww, fd, sizeof(struct frameset_desc) + fd->n * sizeof(struct frame_desc));
for (i = 0; i < neww->n; i++) {
if (neww->f[i].subframe) neww->f[i].subframe = copy_frameset_desc(neww->f[i].subframe);
@@ -470,7 +470,7 @@ static inline void shift_chars(struct part *p, int y, int s)
chr *a;
int l = LEN(y);
if ((unsigned)l > MAXINT / sizeof(chr)) overalloc();
- a = mem_alloc(l * sizeof(chr));
+ a = xmalloc(l * sizeof(chr));
memcpy(a, &POS(0, y), l * sizeof(chr));
set_hchars(p, 0, y, s, ' ', p->attribute);
copy_chars(p, s, y, l, a);
@@ -560,7 +560,7 @@ void html_tag(struct f_data *f, unsigned char *t, int x, int y)
add_conv_str(&tt, &ll, t, (int)strlen(cast_const_char t), -2);
sl = strlen(cast_const_char tt);
if (sl > MAXINT - sizeof(struct tag)) overalloc();
- tag = mem_alloc(sizeof(struct tag) + sl);
+ tag = xmalloc(sizeof(struct tag) + sl);
tag->x = x;
tag->y = y;
strcpy(cast_char tag->name, cast_const_char tt);
@@ -632,7 +632,7 @@ static void put_chars(void *p_, unsigned char *c, int l)
p->utf8_part_len = 0;
if (!l) return;
if ((unsigned)l > (unsigned)MAXINT / sizeof(char_t)) overalloc();
- uni_c = mem_alloc(l * sizeof(char_t));
+ uni_c = xmalloc(l * sizeof(char_t));
ll = 0;
cc = c;
next_utf_char:
@@ -1014,7 +1014,7 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
}
if (data) {
struct node *n;
- n = mem_alloc(sizeof(struct node));
+ n = xmalloc(sizeof(struct node));
n->x = xs;
n->y = ys;
n->xw = !table_level ? MAXINT - 1 : width;
@@ -1331,10 +1331,10 @@ static int sort_srch(struct f_data *f)
int *min, *max;
if ((unsigned)f->y > MAXINT / sizeof(struct search *)) overalloc();
if ((unsigned)f->y > MAXINT / sizeof(int)) overalloc();
- f->slines1 = mem_alloc_mayfail(f->y * sizeof(int));
- f->slines2 = mem_alloc_mayfail(f->y * sizeof(int));
- min = mem_alloc_mayfail(f->y * sizeof(int));
- max = mem_alloc_mayfail(f->y * sizeof(int));
+ f->slines1 = xmalloc(f->y * sizeof(int));
+ f->slines2 = xmalloc(f->y * sizeof(int));
+ min = xmalloc(f->y * sizeof(int));
+ max = xmalloc(f->y * sizeof(int));
if (!f->slines1 || !f->slines2 || !min || !max) {
if (f->slines1) mem_free(f->slines1), f->slines1 = NULL;
if (f->slines2) mem_free(f->slines2), f->slines2 = NULL;
@@ -1469,9 +1469,9 @@ int get_search_data(struct f_data *f)
if (f->search_pos) return 0;
if (get_srch(f)) return -1;
if ((size_t)n_chr > MAX_SIZE_T / sizeof(char_t) || (size_t)n_pos > MAX_SIZE_T / sizeof(struct search)) return -1;
- f->search_chr = mem_alloc_mayfail(n_chr * sizeof(char_t));
+ f->search_chr = xmalloc(n_chr * sizeof(char_t));
if (!f->search_chr) return -1;
- f->search_pos = mem_alloc_mayfail(n_pos * sizeof(struct search));
+ f->search_pos = xmalloc(n_pos * sizeof(struct search));
if (!f->search_pos) {
mem_free(f->search_chr);
f->search_chr = NULL;
diff --git a/html_tbl.c b/html_tbl.c
@@ -812,9 +812,12 @@ static int get_column_widths(struct table *t)
{
int i, j, s, ns;
if ((unsigned)t->x > MAXINT / sizeof(int)) overalloc();
- if (!t->min_c) t->min_c = mem_alloc(t->x * sizeof(int));
- if (!t->max_c) t->max_c = mem_alloc(t->x * sizeof(int));
- if (!t->w_c) t->w_c = mem_alloc(t->x * sizeof(int));
+ if (!t->min_c)
+ t->min_c = xmalloc(t->x * sizeof(int));
+ if (!t->max_c)
+ t->max_c = xmalloc(t->x * sizeof(int));
+ if (!t->w_c)
+ t->w_c = xmalloc(t->x * sizeof(int));
memset(t->min_c, 0, t->x * sizeof(int));
memset(t->max_c, 0, t->x * sizeof(int));
s = 1;
@@ -903,9 +906,9 @@ static void distribute_widths(struct table *t, int width)
memcpy(t->w_c, t->min_c, t->x * sizeof(int));
t->rw = width;
if ((unsigned)t->x > MAXINT / sizeof(int)) overalloc();
- u = mem_alloc(t->x);
- w = mem_alloc(t->x * sizeof(int));
- mx = mem_alloc(t->x * sizeof(int));
+ u = xmalloc(t->x);
+ w = xmalloc(t->x * sizeof(int));
+ mx = xmalloc(t->x * sizeof(int));
while (d) {
int mss, mii;
int p = 0;
@@ -1311,8 +1314,8 @@ static void display_table_frames(struct table *t, int x, int y)
if ((unsigned)t->y > MAXINT) overalloc();
if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) / ((unsigned)t->x + 2) != ((unsigned)t->y + 2)) overalloc();
if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > MAXINT) overalloc();
- fh = mem_alloc((t->x + 2) * (t->y + 1) * sizeof(short));
- fv = mem_alloc((t->x + 1) * (t->y + 2) * sizeof(short));
+ fh = xmalloc((t->x + 2) * (t->y + 1) * sizeof(short));
+ fv = xmalloc((t->x + 1) * (t->y + 2) * sizeof(short));
get_table_frame(t, fv, fh);
cy = y;
@@ -1556,7 +1559,7 @@ void format_table(unsigned char *attr, unsigned char *html, unsigned char *eof,
n->yw = p->yp - n->y + p->cy;
display_complicated_table(t, x, p->cy, &cye);
display_table_frames(t, x, p->cy);
- nn = mem_alloc(sizeof(struct node));
+ nn = xmalloc(sizeof(struct node));
nn->x = n->x;
nn->y = safe_add(p->yp, cye);
nn->xw = n->xw;
@@ -1782,8 +1785,8 @@ static void process_g_table(struct g_part *gp, struct table *t)
if ((unsigned)t->y > MAXINT) overalloc();
if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) / ((unsigned)t->x + 2) != ((unsigned)t->y + 2)) overalloc();
if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > MAXINT) overalloc();
- fh = mem_alloc((t->x + 2) * (t->y + 1) * sizeof(short));
- fv = mem_alloc((t->x + 1) * (t->y + 2) * sizeof(short));
+ fh = xmalloc((t->x + 2) * (t->y + 1) * sizeof(short));
+ fv = xmalloc((t->x + 1) * (t->y + 2) * sizeof(short));
get_table_frame(t, fv, fh);
y = 0;
for (j = 0; j <= t->y; j++) {
@@ -1951,12 +1954,12 @@ void *find_table_cache_entry(unsigned char *start, unsigned char *end, int align
for (tce = table_cache_hash[hash]; tce; tce = tce->hash_next) {
if (tce->start == start && tce->end == end && tce->align == align && tce->m == m && tce->width == width && tce->xs == xs && tce->link_num == link_num) {
if (!F) {
- struct part *p = mem_alloc(sizeof(struct part));
+ struct part *p = xmalloc(sizeof(struct part));
memcpy(p, &tce->u.p, sizeof(struct part));
return p;
#ifdef G
} else {
- struct g_part *gp = mem_alloc(sizeof(struct g_part));
+ struct g_part *gp = xmalloc(sizeof(struct g_part));
memcpy(gp, &tce->u.gp, sizeof(struct g_part));
return gp;
#endif
@@ -1969,7 +1972,7 @@ void *find_table_cache_entry(unsigned char *start, unsigned char *end, int align
void add_table_cache_entry(unsigned char *start, unsigned char *end, int align, int m, int width, int xs, int link_num, void *p)
{
int hash;
- struct table_cache_entry *tce = mem_alloc(sizeof(struct table_cache_entry));
+ struct table_cache_entry *tce = xmalloc(sizeof(struct table_cache_entry));
tce->start = start;
tce->end = end;
tce->align = align;
diff --git a/https.c b/https.c
@@ -143,7 +143,7 @@ links_ssl *getSSL(void)
}
SSL_CTX_set_default_passwd_cb(ctx, ssl_password_callback);
}
- ssl = mem_alloc_mayfail(sizeof(links_ssl));
+ ssl = xmalloc(sizeof(links_ssl));
if (!ssl)
return NULL;
ssl->ctx = contexts[idx];
@@ -354,7 +354,7 @@ static void set_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port,
return;
sl = strlen(cast_const_char host);
if (sl > MAXINT - sizeof(sizeof(struct session_cache_entry))) return;
- sce = mem_alloc(sizeof(struct session_cache_entry) + sl);
+ sce = xmalloc(sizeof(struct session_cache_entry) + sl);
sce->absolute_time = get_absolute_time();
sce->ctx = ctx;
sce->session = s;
diff --git a/img.c b/img.c
@@ -291,7 +291,7 @@ int header_dimensions_known(struct cached_image *cimg)
goto skip_img;
}
if ((unsigned)cimg->width > MAXINT / sizeof(*buf_16) / 3) overalloc();
- buf_16=mem_alloc(sizeof(*buf_16)*3*cimg->width);
+ buf_16 = xmalloc(sizeof(*buf_16) * 3 * cimg->width);
round_color_sRGB_to_48(&red, &green, &blue
, cimg->background_color);
mix_one_color_48(buf_16,cimg->width, red, green, blue);
@@ -333,7 +333,7 @@ int header_dimensions_known(struct cached_image *cimg)
cimg->bmp_used=0;
if (cimg->width && (unsigned)cimg->width * (unsigned)cimg->height / (unsigned)cimg->width != (unsigned)cimg->height) overalloc();
if ((unsigned)cimg->width * (unsigned)cimg->height > (unsigned)MAXINT / cimg->buffer_bytes_per_pixel) overalloc();
- cimg->buffer=mem_alloc_mayfail((size_t)cimg->width * (size_t)cimg->height * (size_t)cimg->buffer_bytes_per_pixel);
+ cimg->buffer = xmalloc((size_t)cimg->width * (size_t)cimg->height * (size_t)cimg->buffer_bytes_per_pixel);
if (!cimg->buffer)
return 1;
if (cimg->buffer_bytes_per_pixel==4
@@ -513,7 +513,7 @@ buffer_to_bitmap_incremental");
}
#endif /* #ifdef DEBUG */
if ((unsigned)cimg->width > MAXINT / max_height / 3 / sizeof(*tmp)) overalloc();
- tmp=mem_alloc(cimg->width*(height<max_height?height:max_height)*3*sizeof(*tmp));
+ tmp = xmalloc(cimg->width*(height<max_height?height:max_height)*3*sizeof(*tmp));
/* Prepare a fake bitmap for dithering */
tmpbmp.x=cimg->width;
if (!use_strip){
@@ -596,7 +596,7 @@ buffer_to_bitmap");
gonna_be_smart=0;
if (ix && (unsigned)ix * (unsigned)iy / (unsigned)ix != (unsigned)iy) overalloc();
if ((unsigned)ix * (unsigned)iy > MAXINT / sizeof(*tmp) / 3) overalloc();
- tmp=mem_alloc_mayfail(ix*iy*3*sizeof(*tmp));
+ tmp = xmalloc(ix*iy*3*sizeof(*tmp));
if (tmp) buffer_to_16(tmp,cimg,cimg->buffer,iy);
if (!cimg->decoder){
mem_free_buffer(cimg);
@@ -1127,7 +1127,7 @@ static void find_or_make_cached_image(struct g_object_image *image, unsigned cha
if (!(cimg = find_cached_image(image->background, url, image->goti.go.xw,
image->goti.go.yw, image->xyw_meaning, scale, aspect))){
/* We have to make a new image cache entry */
- cimg = mem_alloc(sizeof(*cimg));
+ cimg = xmalloc(sizeof(*cimg));
cimg->refcount = 1;
cimg->background_color = image->background;
#ifdef DEBUG
diff --git a/jpeg.c b/jpeg.c
@@ -82,8 +82,8 @@ void jpeg_start(struct cached_image *cimg)
{
struct jpg_decoder *jd;
- global_cinfo=mem_alloc(sizeof(*global_cinfo));
- global_jerr=mem_alloc(sizeof(*global_jerr));
+ global_cinfo = xmalloc(sizeof(*global_cinfo));
+ global_jerr = xmalloc(sizeof(*global_jerr));
global_cinfo->err = jpeg_std_error(&(global_jerr->pub));
global_jerr->pub.error_exit=my_error_exit;
global_jerr->pub.output_message=my_output_message;
@@ -107,7 +107,7 @@ g19_2000:
global_cinfo->src->term_source=nop;
global_cinfo->src->bytes_in_buffer=0;
global_cinfo->src->next_input_byte=NULL;
- cimg->decoder=mem_alloc(sizeof(struct jpg_decoder));
+ cimg->decoder = xmalloc(sizeof(struct jpg_decoder));
jd=(struct jpg_decoder *)cimg->decoder;
jd->cinfo=global_cinfo;
jd->jerr=global_jerr;
@@ -223,7 +223,7 @@ void jpeg_restart(struct cached_image *cimg, unsigned char *data, int length)
}else{
/* If there is no decoder buffer we'll have to allocate
* space for a new buffer */
- deco->jdata=mem_alloc(global_cinfo->src->bytes_in_buffer+length);
+ deco->jdata = xmalloc(global_cinfo->src->bytes_in_buffer+length);
}
/* Copy the data iself into the decoder buffer */
diff --git a/kbd.c b/kbd.c
@@ -303,7 +303,7 @@ void handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
error("ERROR: could not get terminal size");
return;
}
- itrm = mem_alloc(sizeof(struct itrm));
+ itrm = xmalloc(sizeof(struct itrm));
itrm->queue_event = queue_event;
itrm->free_trm = free_trm;
ditrm = itrm;
@@ -523,7 +523,7 @@ static void in_sock(void *itrm_)
EINTRLOOP(rs, unlink(cast_const_char delet));
goto to_je_ale_hnus;
}
- param = mem_alloc(strlen(cast_const_char path) + strlen(cast_const_char delet) + 3);
+ param = xmalloc(strlen(cast_const_char path) + strlen(cast_const_char delet) + 3);
param[0] = fg;
strcpy(cast_char(param + 1), cast_const_char path);
strcpy(cast_char(param + 1 + strlen(cast_const_char path) + 1), cast_const_char delet);
diff --git a/language.c b/language.c
@@ -147,7 +147,7 @@ unsigned char *get_text_translation(unsigned char *text, struct terminal *term)
current_tra[text - dummyarray] = trn;
} else {
if (current_lang_charset && charset != current_lang_charset) {
- current_tra = translation_array[charset] = mem_alloc(sizeof (unsigned char *) * T__N_TEXTS);
+ current_tra = translation_array[charset] = xmalloc(sizeof (unsigned char *) * T__N_TEXTS);
memset(current_tra, 0, sizeof (unsigned char *) * T__N_TEXTS);
goto tr;
}
diff --git a/links.h b/links.h
@@ -305,6 +305,9 @@ extern int F;
} \
} \
+void die(const char *, ...);
+void *xmalloc(size_t);
+
/* error.c */
#define ANSI_BELL "\007"
@@ -389,21 +392,17 @@ static inline int safe_add_function(int x, int y, unsigned char *file, int line)
#define safe_add(x, y) safe_add_function(x, y, (unsigned char *)__FILE__, __LINE__)
-void *mem_alloc_(size_t size, int mayfail);
void *mem_calloc_(size_t size, int mayfail);
void mem_free(void *p);
void *mem_realloc_(void *p, size_t size, int mayfail);
-#define mem_alloc(x) mem_alloc_(x, 0)
#define mem_calloc(x) mem_calloc_(x, 0)
#define mem_realloc(x, y) mem_realloc_(x, y, 0)
-#define mem_alloc_mayfail(x) mem_alloc_(x, 1)
#define mem_calloc_mayfail(x) mem_calloc_(x, 1)
#define mem_realloc_mayfail(x, y) mem_realloc_(x, y, 1)
-static inline void *debug_mem_alloc(unsigned char *f, int l, size_t s, int mayfail) { return mem_alloc_(s, mayfail); }
static inline void *debug_mem_calloc(unsigned char *f, int l, size_t s, int mayfail) { return mem_calloc_(s, mayfail); }
static inline void debug_mem_free(unsigned char *f, int l, void *p) { mem_free(p); }
static inline void *debug_mem_realloc(unsigned char *f, int l, void *p, size_t s, int mayfail) { return mem_realloc_(p, s, mayfail); }
diff --git a/listedit.c b/listedit.c
@@ -924,7 +924,7 @@ static int list_item_delete(struct dialog_data *dlg,struct dialog_item_data *use
if (item==ld->list||list_empty(item->list_entry))return 0; /* head or empty list */
- narez=mem_alloc(sizeof(struct ve_skodarne_je_jeste_vetsi_narez));
+ narez = xmalloc(sizeof(struct ve_skodarne_je_jeste_vetsi_narez));
narez->ld=ld;narez->item=item;narez->dlg=dlg;
txt=ld->type_item(term, item,0);
@@ -1017,7 +1017,7 @@ static int redraw_list_element(struct terminal *term, struct dialog_data *dlg, i
x+=draw_bfu_element(term,dlg->x+DIALOG_LB,y,color,bgcolor,fgcolor,element,(l->type)&4);
break;
case 1:
- xp = mem_alloc(l->depth + 1);
+ xp = xmalloc(l->depth + 1);
memset(xp, 0, l->depth + 1);
xd = l->depth + 1;
for (lx = list_next(l); lx != ld->list; lx = list_next(lx)) {
@@ -1354,7 +1354,7 @@ static int list_event_handler(struct dialog_data *dlg, struct links_event *ev)
{
struct redraw_data *r;
- r=mem_alloc(sizeof(struct redraw_data));
+ r = xmalloc(sizeof(struct redraw_data));
r->ld=ld;
r->dlg=dlg;
@@ -1365,7 +1365,7 @@ static int list_event_handler(struct dialog_data *dlg, struct links_event *ev)
{
struct redraw_data *r;
- r=mem_alloc(sizeof(struct redraw_data));
+ r = xmalloc(sizeof(struct redraw_data));
r->ld=ld;
r->dlg=dlg;
diff --git a/lru.c b/lru.c
@@ -24,7 +24,7 @@ static inline void row_delete(struct lru_entry *ptr)
void lru_insert(struct lru *cache, void *entry, struct lru_entry **row, unsigned bytes_consumed)
{
- struct lru_entry *new_entry = mem_alloc(sizeof(*new_entry));
+ struct lru_entry *new_entry = xmalloc(sizeof(*new_entry));
new_entry->above = NULL;
new_entry->below = cache->top;
diff --git a/main.c b/main.c
@@ -4,6 +4,12 @@
* This file is a part of the Links program, released under GPL.
*/
+#include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "links.h"
int retval = RET_OK;
@@ -11,6 +17,28 @@ int retval = RET_OK;
static void unhandle_basic_signals(struct terminal *);
static void poll_fg(void *);
+void
+die(const char *errstr, ...)
+{
+ va_list ap;
+
+ va_start(ap, errstr);
+ vfprintf(stderr, errstr, ap);
+ va_end(ap);
+ exit(1);
+}
+
+void *
+xmalloc(size_t len)
+{
+ void *p;
+
+ if (!(p = malloc(len)))
+ die("malloc: %s\n", strerror(errno));
+
+ return p;
+}
+
static void sig_intr(void *t_)
{
struct terminal *t = (struct terminal *)t_;
@@ -213,7 +241,7 @@ void gfx_connection(int h)
goto err_close;
if (hard_read(h, (unsigned char *)&info_len, sizeof(int)) != sizeof(int) || info_len < 0)
goto err_close;
- info = mem_alloc(info_len);
+ info = xmalloc(info_len);
if (hard_read(h, info, info_len) != info_len)
goto err_close_free;
term = init_gfx_term(win_func, cwd, info, info_len);
diff --git a/memory.c b/memory.c
@@ -61,7 +61,7 @@ int shrink_memory(int type, int flags)
void register_cache_upcall(int (*upcall)(int), int flags, unsigned char *name)
{
struct cache_upcall *c;
- c = mem_alloc(sizeof(struct cache_upcall) + strlen(cast_const_char name));
+ c = xmalloc(sizeof(struct cache_upcall) + strlen(cast_const_char name));
c->upcall = upcall;
c->flags = (unsigned char)flags;
strcpy(cast_char c->name, cast_const_char name);
diff --git a/menu.c b/menu.c
@@ -306,7 +306,7 @@ static int resource_info(struct terminal *term, struct refresh *r2)
int l;
struct refresh *r;
- r = mem_alloc(sizeof(struct refresh));
+ r = xmalloc(sizeof(struct refresh));
r->term = term;
r->win = NULL;
r->fn = resource_info;
@@ -1437,7 +1437,7 @@ int save_noproxy_list(int charset, unsigned char *result, unsigned char *noproxy
static int check_proxy_noproxy(struct dialog_data *dlg, struct dialog_item_data *di, int (*save)(int, unsigned char *, unsigned char *))
{
- unsigned char *result = mem_alloc(MAX_STR_LEN);
+ unsigned char *result = xmalloc(MAX_STR_LEN);
if (save(term_charset(dlg->win->term), result, di->cdata)) {
mem_free(result);
msg_box(dlg->win->term, NULL, TEXT_(T_BAD_STRING), AL_CENTER, TEXT_(T_BAD_PROXY_SYNTAX), MSG_BOX_END, NULL, 1, TEXT_(T_CANCEL), msg_box_null, B_ENTER | B_ESC);
@@ -2928,7 +2928,7 @@ static void do_file_menu(struct terminal *term, void *xxx, void *ses_)
int x;
int o;
struct menu_item *file_menu, *e;
- file_menu = mem_alloc(sizeof(file_menu11) + sizeof(file_menu12) + sizeof(file_menu21) + sizeof(file_menu22) + sizeof(file_menu3) + 3 * sizeof(struct menu_item));
+ file_menu = xmalloc(sizeof(file_menu11) + sizeof(file_menu12) + sizeof(file_menu21) + sizeof(file_menu22) + sizeof(file_menu3) + 3 * sizeof(struct menu_item));
e = file_menu;
if (!F) {
memcpy(e, file_menu11, sizeof(file_menu11));
@@ -3189,7 +3189,7 @@ static void do_setup_menu(struct terminal *term, void *xxx, void *ses_)
sizeof(setup_menu_6) +
sizeof(setup_menu_7) +
sizeof(setup_menu_8);
- setup_menu = mem_alloc(size);
+ setup_menu = xmalloc(size);
e = setup_menu;
if (!F) {
memcpy(e, setup_menu_2, sizeof(setup_menu_2));
@@ -3327,7 +3327,7 @@ static void does_file_exist(void *d_, unsigned char *file)
unsigned char *msg;
int file_type = 0;
- h = mem_alloc(sizeof(struct does_file_exist_s));
+ h = xmalloc(sizeof(struct does_file_exist_s));
h->fn = d->fn;
h->cancel = d->cancel;
h->flags = d->flags;
@@ -3430,7 +3430,7 @@ void query_file(struct session *ses, unsigned char *url, unsigned char *head, vo
int dfl = 0;
struct does_file_exist_s *h;
- h = mem_alloc(sizeof(struct does_file_exist_s));
+ h = xmalloc(sizeof(struct does_file_exist_s));
fc = get_filename_from_url(url, head, 0);
file = convert(utf8_table, 0, fc, NULL);
diff --git a/objreq.c b/objreq.c
@@ -143,7 +143,7 @@ static int auth_window(struct object_request *rq, unsigned char *realm)
}
}
urealm = convert(term_charset(term), net_cp, realm, NULL);
- d = mem_alloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct auth_dialog) + strlen(cast_const_char get_text_translation(TEXT_(T_ENTER_USERNAME), term)) + strlen(cast_const_char urealm) + 1 + strlen(cast_const_char get_text_translation(TEXT_(T_AT), term)) + strlen(cast_const_char host));
+ d = xmalloc(sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct auth_dialog) + strlen(cast_const_char get_text_translation(TEXT_(T_ENTER_USERNAME), term)) + strlen(cast_const_char urealm) + 1 + strlen(cast_const_char get_text_translation(TEXT_(T_AT), term)) + strlen(cast_const_char host));
memset(d, 0, sizeof(struct dialog) + 5 * sizeof(struct dialog_item) + sizeof(struct auth_dialog));
a = (struct auth_dialog *)((unsigned char *)d + sizeof(struct dialog) + 5 * sizeof(struct dialog_item));
strcpy(cast_char a->msg, cast_const_char get_text_translation(TEXT_(T_ENTER_USERNAME), term));
@@ -243,7 +243,7 @@ static int cert_window(struct object_request *rq)
struct memory_list *ml;
if (!(term = find_terminal(rq->term))) return -1;
h = get_host_name(rq->url);
- cs = mem_alloc(sizeof(struct cert_dialog));
+ cs = xmalloc(sizeof(struct cert_dialog));
cs->term = rq->term;
cs->host = h;
cs->state = rq->stat.state;
diff --git a/png.c b/png.c
@@ -145,7 +145,7 @@ static void png_row_callback(png_structp png_ptr, png_bytep new_row, png_uint_32
*channels);
}else{
if ((unsigned)cimg->width > (unsigned)MAXINT / 2 / channels) overalloc();
- tmp=mem_alloc(cimg->width*2*channels);
+ tmp = xmalloc(cimg->width*2*channels);
a2char_from_unsigned_short(tmp, (unsigned short *)(cimg->buffer
+cimg->buffer_bytes_per_pixel
*cimg->width*row_num), cimg->width*channels);
@@ -208,7 +208,7 @@ error:
png_info_callback, &png_row_callback,
png_end_callback);
if (setjmp(png_jmpbuf(png_ptr))) goto error;
- decoder=mem_alloc(sizeof(*decoder));
+ decoder = xmalloc(sizeof(*decoder));
decoder->png_ptr=png_ptr;
decoder->info_ptr=info_ptr;
cimg->decoder=decoder;
diff --git a/sched.c b/sched.c
@@ -307,7 +307,7 @@ void add_keepalive_socket(struct connection *c, uttime timeout, int protocol_dat
internal("keepalive connection not connected");
goto del;
}
- k = mem_alloc(sizeof(struct k_conn));
+ k = xmalloc(sizeof(struct k_conn));
if (c->netcfg_stamp != netcfg_stamp ||
ssl_not_reusable(c->ssl) ||
(k->port = get_port(c->url)) == -1 ||
@@ -501,7 +501,7 @@ static void run_connection(struct connection *c)
return;
}
if (!(hc = is_host_on_list(c))) {
- hc = mem_alloc(sizeof(struct h_conn));
+ hc = xmalloc(sizeof(struct h_conn));
if (!(hc->host = get_host_name(c->url))) {
mem_free(hc);
goto s_bad_url;
@@ -1086,7 +1086,7 @@ void add_blacklist_entry(unsigned char *host, int flags)
}
sl = strlen(cast_const_char host);
if (sl > MAXINT - sizeof(struct blacklist_entry)) overalloc();
- b = mem_alloc(sizeof(struct blacklist_entry) + sl);
+ b = xmalloc(sizeof(struct blacklist_entry) + sl);
b->flags = flags;
strcpy(cast_char b->host, cast_const_char host);
add_to_list(blacklist, b);
diff --git a/select.c b/select.c
@@ -186,7 +186,7 @@ void register_bottom_half(void (*fn)(void *), void *data)
struct bottom_half *bh;
struct list_head *lbh;
foreach(struct bottom_half, bh, lbh, bottom_halves) if (bh->fn == fn && bh->data == data) return;
- bh = mem_alloc(sizeof(struct bottom_half));
+ bh = xmalloc(sizeof(struct bottom_half));
bh->fn = fn;
bh->data = data;
add_to_list(bottom_halves, bh);
@@ -309,7 +309,7 @@ static void set_event_for_action(int h, void (*func)(void *), struct event **evp
#ifdef EV_PERSIST
evtype |= EV_PERSIST;
#endif
- *evptr = mem_alloc(sizeof_struct_event);
+ *evptr = xmalloc(sizeof_struct_event);
event_set(*evptr, h, evtype, event_callback, *evptr);
if (event_base_set(event_base, *evptr) == -1)
fatal_exit("ERROR: event_base_set failed: %s at %s:%d, handle %d", strerror(errno), sh_file, sh_line, h);
@@ -474,11 +474,11 @@ struct timer *install_timer(uttime t, void (*func)(void *), void *data)
struct timer *tm;
#ifdef USE_LIBEVENT
{
- unsigned char *q = mem_alloc(sizeof_struct_event + sizeof(struct timer));
+ unsigned char *q = xmalloc(sizeof_struct_event + sizeof(struct timer));
tm = (struct timer *)(q + sizeof_struct_event);
}
#else
- tm = mem_alloc(sizeof(struct timer));
+ tm = xmalloc(sizeof(struct timer));
#endif
tm->interval = t;
tm->func = func;
diff --git a/session.c b/session.c
@@ -140,7 +140,7 @@ have_error:
foreach(struct strerror_val, s, ls, strerror_buf) if (!strcmp(cast_const_char s->msg, cast_const_char e)) return s->msg;
sl = strlen(cast_const_char e);
if (sl > MAXINT - sizeof(struct strerror_val)) overalloc();
- s = mem_alloc(sizeof(struct strerror_val) + sl);
+ s = xmalloc(sizeof(struct strerror_val) + sl);
strcpy(cast_char s->msg, cast_const_char e);
add_to_list(strerror_buf, s);
return s->msg;
@@ -1681,7 +1681,7 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char
if ((u = extract_position(url))) mem_free(u);
if (!f->af) {
if (!(f->af = f->fd->af)) {
- f->af = f->fd->af = mem_alloc(sizeof(struct additional_files));
+ f->af = f->fd->af = xmalloc(sizeof(struct additional_files));
f->af->refcount = 1;
init_list(f->af->af);
}
@@ -1693,7 +1693,7 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char
}
sl = strlen(cast_const_char url);
if (sl > MAXINT - sizeof(struct additional_file)) overalloc();
- af = mem_alloc(sizeof(struct additional_file) + sl);
+ af = xmalloc(sizeof(struct additional_file) + sl);
af->use_tag = 0;
af->use_tag2 = 0;
strcpy(cast_char af->url, cast_const_char url);
@@ -1715,14 +1715,14 @@ static void copy_additional_files(struct additional_files **a)
struct list_head *laf;
if (!*a || (*a)->refcount == 1) return;
(*a)->refcount--;
- afs = mem_alloc(sizeof(struct additional_files));
+ afs = xmalloc(sizeof(struct additional_files));
afs->refcount = 1;
init_list(afs->af);
foreachback(struct additional_file, af, laf, (*a)->af) {
struct additional_file *afc;
size_t sl = strlen(cast_const_char af->url);
if (sl > MAXINT - sizeof(struct additional_file)) overalloc();
- afc = mem_alloc(sizeof(struct additional_file) + sl);
+ afc = xmalloc(sizeof(struct additional_file) + sl);
memcpy(afc, af, sizeof(struct additional_file) + sl);
if (af->rq) clone_object(af->rq, &afc->rq);
add_to_list(afs->af, afc);
@@ -1772,7 +1772,7 @@ void refresh_image(struct f_data_c *fd, struct g_object *img, uttime tm)
}
return;
}
- ir = mem_alloc(sizeof(struct image_refresh));
+ ir = xmalloc(sizeof(struct image_refresh));
ir->img = img;
ir->tim = tm;
ir->start = now;
@@ -2334,7 +2334,7 @@ static void type_query_multiple_programs(struct session *ses, unsigned char *ct,
struct memory_list *ml;
unsigned char **text_array;
- text_array = mem_alloc(6 * sizeof(unsigned char *));
+ text_array = xmalloc(6 * sizeof(unsigned char *));
text_array[0] = TEXT_(T_CONTENT_TYPE_IS);
text_array[1] = cast_uchar " ";
text_array[2] = ct;
@@ -2771,7 +2771,7 @@ static int read_session_info(struct session *ses, void *data, int len)
unsigned char *tgt;
if (len<3*(int)sizeof(int)+sz+sz1) goto bla;
if ((unsigned)sz1 >= MAXINT) overalloc();
- tgt=mem_alloc(sz1+1);
+ tgt = xmalloc(sz1 + 1);
memcpy(tgt, (unsigned char*)((int*)data+3)+sz,sz1);
tgt[sz1]=0;
if (ses->wanted_framename) mem_free(ses->wanted_framename), ses->wanted_framename=NULL;
@@ -2782,7 +2782,7 @@ static int read_session_info(struct session *ses, void *data, int len)
unsigned char *u, *uu;
if (len < 3 * (int)sizeof(int) + sz) return -1;
if ((unsigned)sz >= MAXINT) overalloc();
- u = mem_alloc(sz + 1);
+ u = xmalloc(sz + 1);
memcpy(u, (int *)data + 3, sz);
u[sz] = 0;
uu = decode_url(u);
diff --git a/terminal.c b/terminal.c
@@ -48,7 +48,7 @@ unsigned char *get_cwd(void)
unsigned char *buf;
unsigned char *gcr;
while (1) {
- buf = mem_alloc(bufsize);
+ buf = xmalloc(bufsize);
ENULLLOOP(gcr, cast_uchar getcwd(cast_char buf, bufsize));
if (gcr) return buf;
mem_free(buf);
@@ -536,7 +536,7 @@ static void empty_window_handler(struct window *win, struct links_event *ev, int
void add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
{
struct ewd *ewd;
- ewd = mem_alloc(sizeof(struct ewd));
+ ewd = xmalloc(sizeof(struct ewd));
ewd->fn = fn;
ewd->data = data;
ewd->b = 0;
@@ -581,7 +581,7 @@ struct term_spec *new_term_spec(unsigned char *term)
struct term_spec *t;
struct list_head *lt;
foreach(struct term_spec, t, lt, term_specs) if (!casestrcmp(t->term, term)) return t;
- t = mem_alloc(sizeof(struct term_spec));
+ t = xmalloc(sizeof(struct term_spec));
memcpy(t, default_term_spec(term), sizeof(struct term_spec));
if (strlen(cast_const_char term) < MAX_TERM_LEN) strcpy(cast_char t->term, cast_const_char term);
else memcpy(t->term, term, MAX_TERM_LEN - 1), t->term[MAX_TERM_LEN - 1] = 0;
@@ -702,7 +702,7 @@ struct terminal *init_gfx_term(void (*root_window)(struct window *, struct links
ev.x = dev->size.x2;
ev.y = dev->size.y2;
if ((unsigned)len > MAXINT - sizeof(int)) overalloc();
- ptr = mem_alloc(sizeof(int) + len);
+ ptr = xmalloc(sizeof(int) + len);
*ptr = len;
memcpy(ptr + 1, info, len);
ev.b = (long)ptr;
diff --git a/types.c b/types.c
@@ -270,7 +270,7 @@ static void assoc_edit_item(struct dialog_data *dlg, struct list *data, void (*o
safe_strncpy(prog, neww->prog, MAX_STR_LEN);
/* Create the dialog */
- s = mem_alloc(sizeof(struct assoc_ok_struct));
+ s = xmalloc(sizeof(struct assoc_ok_struct));
s->fn = ok_fn;
s->data = ok_arg;
s->dlg = dlg;
@@ -614,7 +614,7 @@ static void ext_edit_item(struct dialog_data *dlg, struct list *data, void (*ok_
safe_strncpy(ct, neww->ct, MAX_STR_LEN);
/* Create the dialog */
- s = mem_alloc(sizeof(struct assoc_ok_struct));
+ s = xmalloc(sizeof(struct assoc_ok_struct));
s->fn = ok_fn;
s->data = ok_arg;
s->dlg = dlg;
@@ -719,11 +719,11 @@ void update_prog(struct list_head *l, unsigned char *p, int s)
mem_free(repl->prog);
goto ss;
}
- repl = mem_alloc(sizeof(struct protocol_program));
+ repl = xmalloc(sizeof(struct protocol_program));
add_to_list(*l, repl);
repl->system = s;
ss:
- repl->prog = mem_alloc(MAX_STR_LEN);
+ repl->prog = xmalloc(MAX_STR_LEN);
safe_strncpy(repl->prog, p, MAX_STR_LEN);
}
@@ -1103,7 +1103,7 @@ struct assoc *get_type_assoc(struct terminal *term, unsigned char *type, int *n)
*n = count;
if (!count) return NULL;
if ((unsigned)count > MAXINT / sizeof(struct assoc)) overalloc();
- assoc_array = mem_alloc(count * sizeof(struct assoc));
+ assoc_array = xmalloc(count * sizeof(struct assoc));
count = 0;
foreach(struct list, l, ll, assoc.list_entry) {
struct assoc *a = get_struct(l, struct assoc, head);
diff --git a/url.c b/url.c
@@ -780,7 +780,7 @@ static unsigned char *puny_encode(unsigned char *s, int len)
if (len > 7 * puny_max_length)
goto err;
- uni = mem_alloc(len * sizeof(unsigned));
+ uni = xmalloc(len * sizeof(unsigned));
uni_l = 0;
for (p = s; p < s + len; ) {
unsigned c;
@@ -903,7 +903,7 @@ static unsigned char *puny_decode(unsigned char *s, int len)
if (len > puny_max_length)
goto err;
- uni = mem_alloc(len * sizeof(unsigned));
+ uni = xmalloc(len * sizeof(unsigned));
uni_l = 0;
if (last_dash) {
diff --git a/view.c b/view.c
@@ -297,7 +297,7 @@ struct line_info *format_text(unsigned char *text, int width, int wrap, int cp)
goto have_it;
}
if (text_len > MAXINT - sizeof(struct format_text_cache_entry)) overalloc();
- ftce = mem_alloc(sizeof(struct format_text_cache_entry) + text_len);
+ ftce = xmalloc(sizeof(struct format_text_cache_entry) + text_len);
memcpy(ftce->copied_text, text, text_len + 1);
ftce->text_ptr = text;
ftce->text_len = (int)text_len;
@@ -375,7 +375,7 @@ static void draw_link(struct terminal *t, struct f_data_c *scr, int l)
q = area_cursor(scr, link->form, fs);
}
if ((unsigned)link->n > MAXINT / sizeof(struct link_bg)) overalloc();
- scr->link_bg = mem_alloc(link->n * sizeof(struct link_bg));
+ scr->link_bg = xmalloc(link->n * sizeof(struct link_bg));
scr->link_bg_n = link->n;
for (i = 0; i < link->n; i++) {
int x = link->pos[i].x + xp - vx;
@@ -1111,7 +1111,7 @@ int dump_to_file(struct f_data *fd, int h)
int x, y;
unsigned char *buf;
int bptr = 0;
- buf = mem_alloc(D_BUF);
+ buf = xmalloc(D_BUF);
for (y = 0; y < fd->y; y++) for (x = 0; x <= fd->data[y].l; x++) {
unsigned c;
if (x == fd->data[y].l) c = '\n';
diff --git a/x.c b/x.c
@@ -571,9 +571,9 @@ static void x_add_to_table(struct graphics_device* gd)
int a=(int)get_window_info(gd)->window & (X_HASH_TABLE_SIZE-1);
int c=x_hash_table[a].count;
- if (!c) {
- x_hash_table[a].pointer=mem_alloc(sizeof(struct graphics_device *));
- } else {
+ if (!c)
+ x_hash_table[a].pointer = xmalloc(sizeof(struct graphics_device *));
+ else {
if ((unsigned)c > MAXINT / sizeof(struct graphics_device *) - 1) overalloc();
x_hash_table[a].pointer=mem_realloc(x_hash_table[a].pointer,(c+1)*sizeof(struct graphics_device *));
}
@@ -1393,7 +1393,7 @@ static struct graphics_device* x_init_device(void)
#ifdef X_DEBUG
MESSAGE("x_init_device\n");
#endif
- gd=mem_alloc(sizeof(struct graphics_device));
+ gd = xmalloc(sizeof(struct graphics_device));
wi=mem_calloc(sizeof(struct window_info));
@@ -1534,13 +1534,7 @@ static int x_get_empty_bitmap(struct bitmap *bmp)
if (pad==x_bitmap_scanline_pad)pad=0;
bmp->skip=bmp->x*x_bitmap_bpp+pad;
bmp->flags=NULL;
- retry:
- if (!(bmp->data=malloc(bmp->skip*bmp->y))) {
- if (out_of_memory(0, NULL, 0))
- goto retry;
- return -1;
- }
- /* on error bmp->data should point to NULL */
+ bmp->data = xmalloc(bmp->skip * bmp->y);
return 0;
}
@@ -1561,7 +1555,7 @@ static void x_register_bitmap(struct bitmap *bmp)
x_translate_colors(bmp->data, bmp->x, bmp->y, bmp->skip);
/* alloc struct x_bitmapa */
- p=mem_alloc(sizeof(struct x_pixmapa));
+ p = xmalloc(sizeof(struct x_pixmapa));
/* alloc XImage in client's memory */
retry:
@@ -1584,7 +1578,7 @@ static void x_register_bitmap(struct bitmap *bmp)
}
x_prepare_for_failure();
- pixmap=mem_alloc(sizeof(Pixmap));
+ pixmap = xmalloc(sizeof(Pixmap));
(*pixmap)=XCreatePixmap(x_display,fake_window,bmp->x,bmp->y,x_depth);
if (x_test_for_failure()) {
if (*pixmap) {
@@ -2010,7 +2004,7 @@ static void *x_prepare_strip(struct bitmap *bmp, int top, int lines)
case X_TYPE_PIXMAP:
retry:
- x_data=malloc(bmp->skip*lines);
+ x_data = xmalloc(bmp->skip * lines);
if (!x_data) {
if (out_of_memory(0, NULL, 0))
goto retry;