links

lynx-like text mode web browser
git clone anongit@rnpnr.xyz:links.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 1d3daaf16f610bb82d98ddf2cfe2e04cd5bac999
Parent: 0fc1f28a22a816fc88eee18b19a9be495d4e467f
Author: opask
Date:   Tue, 14 Aug 2018 17:50:43 -0600

replace MAXINT with actual constant INT_MAX

Diffstat:
Mauth.c | 2+-
Mbfu.c | 40++++++++++++++++++++--------------------
Mcache.c | 6+++---
Mcharsets.c | 6+++---
Mcompress.c | 2+-
Mconnect.c | 6+++---
Mcookies.c | 2+-
Mdefault.c | 14+++++++-------
Mdip.c | 60++++++++++++++++++++++++++++++------------------------------
Mdither.c | 4++--
Mdns.c | 2+-
Mfile.c | 6+++---
Mgif.c | 4++--
Mhtml.c | 22+++++++++++-----------
Mhtml_gr.c | 16++++++++--------
Mhtml_r.c | 36++++++++++++++++++------------------
Mhtml_tbl.c | 62+++++++++++++++++++++++++++++++-------------------------------
Mhttp.c | 4++--
Mhttps.c | 2+-
Mimg.c | 12++++++------
Mjpeg.c | 2+-
Mkbd.c | 2+-
Mlinks.h | 6+++---
Mmain.c | 4++--
Mmenu.c | 10+++++-----
Mos_dep.c | 2+-
Msched.c | 2+-
Mselect.c | 4++--
Msession.c | 20++++++++++----------
Mstring.c | 14+++++++-------
Mterminal.c | 16++++++++--------
Mtypes.c | 4++--
Mview.c | 22+++++++++++-----------
Mview_gr.c | 8++++----
Mx.c | 4++--
35 files changed, 214 insertions(+), 214 deletions(-)

diff --git a/auth.c b/auth.c @@ -25,7 +25,7 @@ unsigned char *base64_encode(unsigned char *in, int inlen, unsigned char *prefix int col; int prefix_len = (int)strlen(cast_const_char prefix); int suffix_len = (int)strlen(cast_const_char suffix); - if (inlen > MAXINT / 2) overalloc(); + if (inlen > INT_MAX / 2) overalloc(); data_len = ((inlen + 2) / 3) * 4; if (line_bits >= 0) { line_mask = (1 << line_bits) - 1; diff --git a/bfu.c b/bfu.c @@ -16,12 +16,12 @@ struct memory_list *getml(void *p, ...) void *q = p; va_start(ap, p); while (q) { - if (n == MAXINT) + if (n == INT_MAX) overalloc(); n++; q = va_arg(ap, void *); } - if ((unsigned)n > (MAXINT - sizeof(struct memory_list)) / sizeof(void *)) + if ((unsigned)n > (INT_MAX - sizeof(struct memory_list)) / sizeof(void *)) overalloc(); ml = xmalloc(sizeof(struct memory_list) + n * sizeof(void *)); ml->n = n; @@ -49,11 +49,11 @@ void add_to_ml(struct memory_list **ml, ...) } va_start(ap, ml); while ((q = va_arg(ap, void *))) { - if (n == MAXINT) + if (n == INT_MAX) overalloc(); n++; } - if ((unsigned)n + (unsigned)((*ml)->n) > (MAXINT - sizeof(struct memory_list)) / sizeof(void *)) + if ((unsigned)n + (unsigned)((*ml)->n) > (INT_MAX - sizeof(struct memory_list)) / sizeof(void *)) overalloc(); nml = xrealloc(*ml, sizeof(struct memory_list) + (n + (*ml)->n) * sizeof(void *)); @@ -177,7 +177,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)) + if (i == (INT_MAX - sizeof(struct menu)) / sizeof(unsigned)) overalloc(); menu = xmalloc(sizeof(struct menu) + (!i ? 0 : i - 1) * sizeof(unsigned)); menu->selected = selected; @@ -192,7 +192,7 @@ void do_menu_selected(struct terminal *term, struct menu_item *items, void *data items[i].hotkey, menu->hotkeys, i); #ifdef G if (F) { - if ((unsigned)menu->ni > MAXINT / sizeof(unsigned char *)) + if ((unsigned)menu->ni > INT_MAX / sizeof(unsigned char *)) overalloc(); menu->hktxt1 = mem_calloc(menu->ni * sizeof(unsigned char *)); menu->hktxt2 = mem_calloc(menu->ni * sizeof(unsigned char *)); @@ -641,7 +641,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(); + for (i = 0; items[i].text; i++) if (i == (INT_MAX - sizeof(struct mainmenu)) / sizeof(unsigned)) overalloc(); menu = xmalloc(sizeof(struct mainmenu) + (!i ? 0 : i - 1) * sizeof(unsigned)); menu->selected = sel == -1 ? 0 : sel; menu->ni = i; @@ -837,9 +837,9 @@ void add_to_menu(struct menu_item **mi, unsigned char *text, unsigned char *rtex n = pos; if ((*mi)[n].text) internal("invalid menu position %d", n); } else { - for (n = 0; (*mi)[n].text; n++) if (n == MAXINT) overalloc(); + for (n = 0; (*mi)[n].text; n++) if (n == INT_MAX) overalloc(); } - if (((unsigned)n + 2) > MAXINT / sizeof(struct menu_item)) + if (((unsigned)n + 2) > INT_MAX / sizeof(struct menu_item)) overalloc(); mii = xrealloc(*mi, (n + 2) * sizeof(struct menu_item)); *mi = mii; @@ -858,10 +858,10 @@ void do_dialog(struct terminal *term, struct dialog *dlg, struct memory_list *ml struct dialog_item *d; int n = 0; for (d = dlg->items; d->type != D_END; d++) { - if (n == MAXINT) overalloc(); + if (n == INT_MAX) overalloc(); n++; } - if ((unsigned)n > (MAXINT - sizeof(struct dialog_data)) / sizeof(struct dialog_item_data)) overalloc(); + if ((unsigned)n > (INT_MAX - sizeof(struct dialog_data)) / sizeof(struct dialog_item_data)) overalloc(); dd = mem_calloc(sizeof(struct dialog_data) + sizeof(struct dialog_item_data) * n); dd->dlg = dlg; dd->n = n; @@ -1228,10 +1228,10 @@ static void do_tab_compl(struct terminal *term, struct list_head *history, struc struct list_head *lhi; struct menu_item *items = NULL; foreach(struct history_item, hi, lhi, *history) { - unsigned char *s = dlg_get_history_string(term, hi, MAXINT); + unsigned char *s = dlg_get_history_string(term, hi, INT_MAX); if (!strncmp(cast_const_char cdata, cast_const_char s, l)) { if (!(n & (ALLOC_GR - 1))) { - if ((unsigned)n > MAXINT / sizeof(struct menu_item) - ALLOC_GR - 1) + if ((unsigned)n > INT_MAX / sizeof(struct menu_item) - ALLOC_GR - 1) overalloc(); items = xrealloc(items, (n + ALLOC_GR + 1) @@ -1245,7 +1245,7 @@ static void do_tab_compl(struct terminal *term, struct list_head *history, struc items[n].data = hi; items[n].in_m = 0; items[n].free_i = 3; - if (n == MAXINT) overalloc(); + if (n == INT_MAX) overalloc(); n++; } else free(s); @@ -1299,7 +1299,7 @@ void dialog_func(struct window *win, struct links_event *ev, int fwd) foreach(struct history_item, j, lj, di->item->history->items) { struct history_item *hi; size_t sl = strlen(cast_const_char j->str); - if (sl > MAXINT - sizeof(struct history_item)) overalloc(); + if (sl > INT_MAX - sizeof(struct history_item)) overalloc(); hi = xmalloc(sizeof(struct history_item) + sl); strcpy(cast_char hi->str, cast_const_char j->str); add_to_list(di->history, hi); @@ -2212,14 +2212,14 @@ void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title do { text = va_arg(ap, unsigned char *); udatan++; - if ((unsigned)udatan > MAXINT / sizeof(unsigned char *)) + if ((unsigned)udatan > INT_MAX / sizeof(unsigned char *)) overalloc(); udata = xrealloc(udata, udatan * sizeof(unsigned char *)); udata[udatan - 1] = text; } while (text); udata2 = va_arg(ap, void *); n = va_arg(ap, int); - if ((unsigned)n > (MAXINT - sizeof(struct dialog)) / sizeof(struct dialog_item) - 1) overalloc(); + if ((unsigned)n > (INT_MAX - sizeof(struct dialog)) / sizeof(struct dialog_item) - 1) overalloc(); dlg = mem_calloc(sizeof(struct dialog) + (n + 1) * sizeof(struct dialog_item)); dlg->title = title; dlg->fn = msg_box_fn; @@ -2264,7 +2264,7 @@ void add_to_history(struct terminal *term, struct history *h, unsigned char *t) s = t; } l = strlen(cast_const_char s); - if (l > MAXINT - sizeof(struct history_item)) overalloc(); + if (l > INT_MAX - sizeof(struct history_item)) overalloc(); hi = xmalloc(sizeof(struct history_item) + l); memcpy(hi->str, s, l + 1); if (term) @@ -2353,8 +2353,8 @@ void input_field(struct terminal *term, struct memory_list *ml, unsigned char *t unsigned char *field; va_list va; int i; - if ((unsigned)n > MAXINT / sizeof(struct dialog_item) - 2) overalloc(); - if ((unsigned)l > MAXINT - sizeof(struct dialog) - (2 + n) * sizeof(struct dialog_item)) overalloc(); + if ((unsigned)n > INT_MAX / sizeof(struct dialog_item) - 2) overalloc(); + if ((unsigned)l > INT_MAX - sizeof(struct dialog) - (2 + n) * sizeof(struct dialog_item)) overalloc(); dlg = mem_calloc(sizeof(struct dialog) + (2 + n) * sizeof(struct dialog_item) + l); *(field = (unsigned char *)dlg + sizeof(struct dialog) + (2 + n) * sizeof(struct dialog_item)) = 0; if (def) { diff --git a/cache.c b/cache.c @@ -251,11 +251,11 @@ have_f: goto ch_o; } } - if (C_ALIGN(length) > MAXINT - sizeof(struct fragment) + if (C_ALIGN(length) > INT_MAX - sizeof(struct fragment) || C_ALIGN(length) < 0) overalloc(); ca = C_ALIGN(length); - if (ca > MAXINT - (int)sizeof(struct fragment) || ca < 0) + if (ca > INT_MAX - (int)sizeof(struct fragment) || ca < 0) return S_LARGE_FILE; nf = xmalloc(sizeof(struct fragment) + (size_t)ca); sf(length); @@ -333,7 +333,7 @@ int defrag_entry(struct cache_entry *e) return S_LARGE_FILE; l += list_struct(h, struct fragment)->length; } - if (l > MAXINT - (int)sizeof(struct fragment)) + if (l > INT_MAX - (int)sizeof(struct fragment)) return S_LARGE_FILE; n = xmalloc(sizeof(struct fragment) + (size_t)l); n->offset = 0; diff --git a/charsets.c b/charsets.c @@ -440,7 +440,7 @@ unsigned char *convert_string(struct conv_table *ct, unsigned char *c, int l, st put_c: buffer[bp++] = c[pp++]; if (!(bp & (ALLOC_GR - 1))) { - if ((unsigned)bp > MAXINT - ALLOC_GR) + if ((unsigned)bp > INT_MAX - ALLOC_GR) overalloc(); buffer = xrealloc(buffer, bp + ALLOC_GR); } @@ -473,7 +473,7 @@ unsigned char *convert_string(struct conv_table *ct, unsigned char *c, int l, st if (!e[1]) { buffer[bp++] = e[0]; if (!(bp & (ALLOC_GR - 1))) { - if ((unsigned)bp > MAXINT - ALLOC_GR) + if ((unsigned)bp > INT_MAX - ALLOC_GR) overalloc(); buffer = xrealloc(buffer, bp + ALLOC_GR); } @@ -482,7 +482,7 @@ unsigned char *convert_string(struct conv_table *ct, unsigned char *c, int l, st while (*e) { buffer[bp++] = *(e++); if (!(bp & (ALLOC_GR - 1))) { - if ((unsigned)bp > MAXINT - ALLOC_GR) + if ((unsigned)bp > INT_MAX - ALLOC_GR) overalloc(); buffer = xrealloc(buffer, bp + ALLOC_GR); } diff --git a/compress.c b/compress.c @@ -18,7 +18,7 @@ static int display_error(struct terminal *term, unsigned char *msg, int *errp) static void decoder_memory_init(unsigned char **p, size_t *size, off_t init_length) { - if (init_length > 0 && init_length < MAXINT) *size = (int)init_length; + if (init_length > 0 && init_length < INT_MAX) *size = (int)init_length; else *size = 4096; *p = xmalloc(*size); } diff --git a/connect.c b/connect.c @@ -142,7 +142,7 @@ void make_connection(struct connection *c, int port, int *sock, void (*func)(str if (c->newconn) internal("already making a connection"); sl = strlen(cast_const_char host); - if (sl > MAXINT - sizeof(struct conn_info)) overalloc(); + if (sl > INT_MAX - sizeof(struct conn_info)) overalloc(); b = mem_calloc(sizeof(struct conn_info) + sl); b->func = func; b->sock = sock; @@ -823,7 +823,7 @@ static void write_select(void *c_) void write_to_socket(struct connection *c, int s, unsigned char *data, int len, void (*write_func)(struct connection *)) { struct write_buffer *wb; - if ((unsigned)len > MAXINT - sizeof(struct write_buffer)) overalloc(); + if ((unsigned)len > INT_MAX - sizeof(struct write_buffer)) overalloc(); wb = xmalloc(sizeof(struct write_buffer) + len); wb->sock = s; wb->len = len; @@ -853,7 +853,7 @@ static void read_select(void *c_) set_handlers(rb->sock, NULL, NULL, NULL); read_more: - if ((unsigned)rb->len > MAXINT - sizeof(struct read_buffer) - READ_SIZE) + if ((unsigned)rb->len > INT_MAX - sizeof(struct read_buffer) - READ_SIZE) overalloc(); rb = xrealloc(rb, sizeof(struct read_buffer) + rb->len + READ_SIZE); c->buffer = rb; diff --git a/cookies.c b/cookies.c @@ -142,7 +142,7 @@ static void accept_cookie(struct cookie *c) if (!casestrcmp(cd->domain, c->domain)) return; sl = strlen((const char *)c->domain); - if (sl > MAXINT - sizeof(struct c_domain)) + if (sl > INT_MAX - sizeof(struct c_domain)) overalloc(); cd = xmalloc(sizeof(struct c_domain) + sl); strcpy(cast_char cd->domain, cast_const_char c->domain); diff --git a/default.c b/default.c @@ -55,7 +55,7 @@ static unsigned char *p_arse_options(int argc, unsigned char *argv[], struct opt unsigned char *e, *u = NULL; int i; for (i = 0; i < argc; i++) { - if (strlen(cast_const_char argv[i]) >= MAXINT) { + if (strlen(cast_const_char argv[i]) >= INT_MAX) { fprintf(stderr, "Too long parameter\n"); return NULL; } @@ -253,7 +253,7 @@ try_new_count: h = c_open3(tmp_name, O_WRONLY | O_NOCTTY | O_CREAT | O_TRUNC | O_EXCL, 0600); if (h == -1) { err = errno; - if (err == EEXIST && count < MAXINT) { + if (err == EEXIST && count < INT_MAX) { count++; free(tmp_name); goto try_new_count; @@ -816,7 +816,7 @@ struct driver_param *get_driver_param(unsigned char *n) struct list_head *ldp; foreach(struct driver_param, dp, ldp, driver_params) if (!casestrcmp(dp->name, n)) return dp; sl = strlen(cast_const_char n); - if (sl > MAXINT - sizeof(struct driver_param)) overalloc(); + if (sl > INT_MAX - sizeof(struct driver_param)) overalloc(); dp = mem_calloc(sizeof(struct driver_param) + sl); dp->kbd_codepage = -1; strcpy(cast_char dp->name, cast_const_char n); @@ -1593,7 +1593,7 @@ static struct option links_options[] = { {1, setstr_cmd, NULL, NULL, 0, MAX_STR_LEN, default_target, NULL, "target"}, {1, setstr_cmd, NULL, NULL, 0, MAX_STR_LEN, ggr_mode, NULL, "mode"}, {1, setstr_cmd, NULL, NULL, 0, MAX_STR_LEN, ggr_display, NULL, "display"}, - {1, gen_cmd, num_rd, NULL, 0, MAXINT, &base_session, NULL, "base-session"}, + {1, gen_cmd, num_rd, NULL, 0, INT_MAX, &base_session, NULL, "base-session"}, {1, set_cmd, NULL, NULL, 0, 0, &force_html, NULL, "force-html"}, {1, dump_cmd, NULL, NULL, D_SOURCE, 0, NULL, NULL, "source"}, {1, dump_cmd, NULL, NULL, D_DUMP, 0, NULL, NULL, "dump"}, @@ -1611,9 +1611,9 @@ static struct option links_options[] = { {1, set_cmd, NULL, NULL, 0, 0, &disable_libevent, NULL, "no-libevent"}, {1, gen_cmd, num_rd, num_wr, 0, 1, &download_utime, "download_utime", "download-utime"}, {1, gen_cmd, num_rd, num_wr, 0, 999, &max_format_cache_entries, "format_cache_size", "format-cache-size"}, - {1, gen_cmd, num_rd, num_wr, 0, MAXINT, &memory_cache_size, "memory_cache_size", "memory-cache-size"}, - {1, gen_cmd, num_rd, num_wr, 0, MAXINT, &image_cache_size, "image_cache_size", "image-cache-size"}, - {1, gen_cmd, num_rd, num_wr, 0, MAXINT, &font_cache_size, "font_cache_size", "font-cache-size"}, + {1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &memory_cache_size, "memory_cache_size", "memory-cache-size"}, + {1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &image_cache_size, "image_cache_size", "image-cache-size"}, + {1, gen_cmd, num_rd, num_wr, 0, INT_MAX, &font_cache_size, "font_cache_size", "font-cache-size"}, {1, gen_cmd, num_rd, num_wr, 0, 1, &aggressive_cache, "http_bugs.aggressive_cache", "aggressive-cache"}, {1, gen_cmd, num_rd, num_wr, 0, 4, &ipv6_options.addr_preference, "ipv6.address_preference", "address-preference"}, {1, proxy_cmd, str_rd, str_wr, 0, MAX_STR_LEN, proxies.http_proxy, "http_proxy", "http-proxy"}, diff --git a/dip.c b/dip.c @@ -277,7 +277,7 @@ static void enlarge_gray_horizontal(unsigned char *in, int ix, int y, unsigned char *inptr; if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc(); - if ((unsigned)ox * (unsigned)y > MAXINT) overalloc(); + if ((unsigned)ox * (unsigned)y > INT_MAX) overalloc(); outptr = xmalloc(ox * y); inptr=in; *out=outptr; @@ -291,7 +291,7 @@ static void enlarge_gray_horizontal(unsigned char *in, int ix, int y, free(in); }else{ total=(ix-1)*(ox-1); - if ((unsigned)y > MAXINT / sizeof(*col_buf)) overalloc(); + if ((unsigned)y > INT_MAX / sizeof(*col_buf)) overalloc(); col_buf = xmalloc(y * sizeof(*col_buf)); bias_buf_gray(col_buf, y, half); out_pos=0; @@ -343,7 +343,7 @@ static void enlarge_color_horizontal(unsigned short *in, int ix, int y, return; } if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc(); - if ((unsigned)ox * (unsigned)y > MAXINT / 3 / sizeof(*out)) overalloc(); + if ((unsigned)ox * (unsigned)y > INT_MAX / 3 / sizeof(*out)) overalloc(); out = xmalloc(sizeof(*out) * 3 * ox * y); *outa=out; if (!out) { @@ -361,11 +361,11 @@ static void enlarge_color_horizontal(unsigned short *in, int ix, int y, return; } - if ((unsigned)y > (MAXINT) / 3 / sizeof(*col_buf)) + if ((unsigned)y > (INT_MAX) / 3 / sizeof(*col_buf)) overalloc(); alloc_size = (int)(y*3*sizeof(*col_buf)); alloc_size = (alloc_size) & ~(0); - if (alloc_size > MAXINT) + if (alloc_size > INT_MAX) overalloc(); col_buf = xmalloc(alloc_size); { @@ -419,11 +419,11 @@ static void scale_gray_horizontal(unsigned char *in, int ix, int y, return; } if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc(); - if ((unsigned)ox * (unsigned)y > MAXINT) overalloc(); + if ((unsigned)ox * (unsigned)y > INT_MAX) overalloc(); outptr = xmalloc(ox * y); inptr=in; *out=outptr; - if ((unsigned)y > MAXINT / sizeof(*col_buf)) overalloc(); + if ((unsigned)y > INT_MAX / sizeof(*col_buf)) overalloc(); col_buf = xmalloc(y * sizeof(*col_buf)); bias_buf_gray(col_buf, y, ix>>1); out_pos=0; @@ -481,7 +481,7 @@ static void scale_color_horizontal(unsigned short *in, int ix, int y, return; } if (ox && (unsigned)ox * (unsigned)y / (unsigned)ox != (unsigned)y) overalloc(); - if ((unsigned)ox * (unsigned)y > MAXINT / 3 / sizeof(*out)) overalloc(); + if ((unsigned)ox * (unsigned)y > INT_MAX / 3 / sizeof(*out)) overalloc(); out = xmalloc(sizeof(*out) * 3 * ox * y); *outa=out; if (!out) { @@ -489,11 +489,11 @@ static void scale_color_horizontal(unsigned short *in, int ix, int y, return; } - if ((unsigned)y > (MAXINT) / 3 / sizeof(*col_buf)) + if ((unsigned)y > (INT_MAX) / 3 / sizeof(*col_buf)) overalloc(); alloc_size = (int)(y*3*sizeof(*col_buf)); alloc_size = (alloc_size) & ~(0); - if (alloc_size > MAXINT) + if (alloc_size > INT_MAX) overalloc(); col_buf = xmalloc(alloc_size); { @@ -544,7 +544,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(); + if ((unsigned)x * (unsigned)oy > INT_MAX) overalloc(); outptr = xmalloc(oy * x); *out=outptr; for(;oy;oy--,outptr+=x) @@ -555,12 +555,12 @@ static void enlarge_gray_vertical(unsigned char *in, int x, int iy, *out=in; }else{ if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc(); - if ((unsigned)x * (unsigned)oy > MAXINT) overalloc(); + if ((unsigned)x * (unsigned)oy > INT_MAX) overalloc(); outptr = xmalloc(oy*x); inptr=in; *out=outptr; total=(iy-1)*(oy-1); - if ((unsigned)x > MAXINT / sizeof(*row_buf)) overalloc(); + if ((unsigned)x > INT_MAX / sizeof(*row_buf)) overalloc(); row_buf = xmalloc(x * sizeof(*row_buf)); bias_buf_gray(row_buf, x, half); out_pos=0; @@ -606,7 +606,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(); + if ((unsigned)x * (unsigned)oy > INT_MAX / 3 / sizeof(*out)) overalloc(); out = xmalloc(sizeof(*out) * 3 * oy * x); *outa=out; if (!out) { @@ -622,11 +622,11 @@ static void enlarge_color_vertical(unsigned short *in, int x, int iy, return; } - if ((unsigned)x > (MAXINT) / 3 / sizeof(*row_buf)) + if ((unsigned)x > (INT_MAX) / 3 / sizeof(*row_buf)) overalloc(); alloc_size = (int)(x*3*sizeof(*row_buf)); alloc_size = (alloc_size) & ~(0); - if (alloc_size > MAXINT) + if (alloc_size > INT_MAX) overalloc(); row_buf = xmalloc(alloc_size); { @@ -682,11 +682,11 @@ static void scale_gray_vertical(unsigned char *in, int x, int iy, return; } if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc(); - if ((unsigned)x * (unsigned)oy > MAXINT) overalloc(); + if ((unsigned)x * (unsigned)oy > INT_MAX) overalloc(); outptr = xmalloc(x * oy); inptr=in; *out=outptr; - if ((unsigned)x > MAXINT / sizeof(*row_buf)) overalloc(); + if ((unsigned)x > INT_MAX / sizeof(*row_buf)) overalloc(); row_buf=mem_calloc(x*sizeof(*row_buf)); bias_buf_gray(row_buf, x, iy>>1); out_pos=0; @@ -742,18 +742,18 @@ static void scale_color_vertical(unsigned short *in, int x, int iy, return; } if (x && (unsigned)x * (unsigned)oy / (unsigned)x != (unsigned)oy) overalloc(); - if ((unsigned)x * (unsigned)oy > MAXINT / 3 / sizeof(*out)) overalloc(); + if ((unsigned)x * (unsigned)oy > INT_MAX / 3 / sizeof(*out)) overalloc(); out = xmalloc(sizeof(*out) * 3 * oy * x); *outa=out; if (!out) { free(in); return; } - if ((unsigned)x > (MAXINT) / 3 / sizeof(*row_buf)) + if ((unsigned)x > (INT_MAX) / 3 / sizeof(*row_buf)) overalloc(); alloc_size = (int)(x*3*sizeof(*row_buf)); alloc_size = (alloc_size) & ~(0); - if (alloc_size > MAXINT) + if (alloc_size > INT_MAX) overalloc(); row_buf = xmalloc(alloc_size); { @@ -803,7 +803,7 @@ static void scale_gray(unsigned char *in, int ix, int iy, if (!ix||!iy){ free(in); if (ox && (unsigned)ox * (unsigned)oy / (unsigned)ox != (unsigned)oy) overalloc(); - if ((unsigned)ox * (unsigned)oy > MAXINT) overalloc(); + if ((unsigned)ox * (unsigned)oy > INT_MAX) overalloc(); *out=mem_calloc(ox*oy); return; } @@ -831,7 +831,7 @@ static void decimate_3(unsigned short **data0, int x, int y) if (!data) return; if (x && (unsigned)x * (unsigned)y / (unsigned)x != (unsigned)y) overalloc(); - if ((unsigned)x * (unsigned)y > MAXINT / 3 / sizeof(**data0)) overalloc(); + if ((unsigned)x * (unsigned)y > INT_MAX / 3 / sizeof(**data0)) overalloc(); futuresize=x*y*3*(int)sizeof(**data0); #ifdef DEBUG @@ -906,7 +906,7 @@ void scale_color(unsigned short *in, int ix, int iy, unsigned short **out, if (!ix||!iy){ free(in); if (ox && (unsigned)ox * (unsigned)oy / (unsigned)ox != (unsigned)oy) overalloc(); - if ((unsigned)ox * (unsigned)oy > MAXINT / 3 / sizeof(**out)) overalloc(); + if ((unsigned)ox * (unsigned)oy > INT_MAX / 3 / sizeof(**out)) overalloc(); *out = mem_calloc(ox * oy * sizeof(**out) * 3); return; } @@ -1539,9 +1539,9 @@ const unsigned char *png_data, int png_length) number_of_passes=png_set_interlace_handling(png_ptr); 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(); + if ((unsigned)*x * (unsigned)*y > INT_MAX) overalloc(); *dest = xmalloc(*x * (*y)); - if ((unsigned)*y > MAXINT / sizeof(*ptrs)) overalloc(); + if ((unsigned)*y > INT_MAX / sizeof(*ptrs)) overalloc(); ptrs = xmalloc(*y * sizeof(*ptrs)); for (y1=0;y1<*y;y1++) ptrs[y1]=*dest+*x*y1; for (;number_of_passes;number_of_passes--){ @@ -1575,7 +1575,7 @@ const unsigned char *png_data, int png_length, struct style *style) ix=*x+2; /* There is one-pixel border around */ iy=y+2; if (ix && (unsigned)ix * (unsigned)iy / (unsigned)ix != (unsigned)iy) overalloc(); - if ((unsigned)ix * (unsigned)iy > MAXINT) overalloc(); + if ((unsigned)ix * (unsigned)iy > INT_MAX) overalloc(); interm2 = xmalloc(ix * iy); i2ptr=interm2+ix+1; dptr=*dest; @@ -1643,7 +1643,7 @@ static struct font_cache_entry *supply_color_cache_entry(struct style *style, st neww->mono_height=style->mono_height; 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(); + if ((unsigned)neww->bitmap.x * (unsigned)neww->bitmap.y > INT_MAX / 3 / sizeof(*primary_data)) overalloc(); primary_data = xmalloc(3 * neww->bitmap.x * neww->bitmap.y * sizeof(*primary_data)); /* We assume the gamma of HTML styles is in sRGB space */ @@ -2123,7 +2123,7 @@ struct style *g_invert_style(struct style *old) st->underline_color=dip_get_color_sRGB( (st->r1<<16)|(st->g1<<8)|(st->b1)); } - if ((unsigned)n_fonts > MAXINT / sizeof(*st->table)) overalloc(); + if ((unsigned)n_fonts > INT_MAX / sizeof(*st->table)) overalloc(); length=(int)sizeof(*st->table)*(n_fonts-1); st->table = xmalloc(length); memcpy(st->table,old->table,length); @@ -2171,7 +2171,7 @@ struct style *g_get_style(int fg, int bg, int size, unsigned char *font, int fla /* We have to get a foreground color for underlining */ st->underline_color=dip_get_color_sRGB(fg); } - if ((unsigned)n_fonts > MAXINT / sizeof(*st->table)) overalloc(); + if ((unsigned)n_fonts > INT_MAX / sizeof(*st->table)) overalloc(); 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); diff --git a/dither.c b/dither.c @@ -784,7 +784,7 @@ void dither(unsigned short *in, struct bitmap *out) { int *dregs; - if ((unsigned)out->x > MAXINT / 3 / sizeof(*dregs)) overalloc(); + if ((unsigned)out->x > INT_MAX / 3 / sizeof(*dregs)) overalloc(); dregs=mem_calloc(out->x*3*sizeof(*dregs)); (*dither_fn_internal)(in, out, dregs); free(dregs); @@ -796,7 +796,7 @@ int *dither_start(unsigned short *in, struct bitmap *out) { int *dregs; - if ((unsigned)out->x > MAXINT / 3 / sizeof(*dregs)) overalloc(); + if ((unsigned)out->x > INT_MAX / 3 / sizeof(*dregs)) overalloc(); dregs=mem_calloc(out->x*3*sizeof(*dregs)); (*dither_fn_internal)(in, out, dregs); return dregs; diff --git a/dns.c b/dns.c @@ -333,7 +333,7 @@ static void end_dns_lookup(struct dnsquery *q, int a) goto e; check_dns_cache_addr_preference(); sl = strlen(cast_const_char q->name); - if (sl > MAXINT - sizeof(struct dnsentry)) + if (sl > INT_MAX - sizeof(struct dnsentry)) overalloc(); dnsentry = xmalloc(sizeof(struct dnsentry) + sl); strcpy(cast_char dnsentry->name, cast_const_char q->name); diff --git a/file.c b/file.c @@ -311,7 +311,7 @@ void file_func(struct connection *c) if (strspn(cast_const_char n, dir_sep('\\') ? "/\\" : "/") == strlen(cast_const_char n)) continue; } - if ((unsigned)dirl > MAXINT / sizeof(struct dirs) - 1) + if ((unsigned)dirl > INT_MAX / sizeof(struct dirs) - 1) overalloc(); dir = xrealloc(dir, (dirl + 1) * sizeof(struct dirs)); dir[dirl].f = stracpy(cast_uchar de->d_name); @@ -343,7 +343,7 @@ void file_func(struct connection *c) do { free(buf); size += ALLOC_GR; - if ((unsigned)size > MAXINT) overalloc(); + if ((unsigned)size > INT_MAX) overalloc(); buf = xmalloc(size); EINTRLOOP(r, (int)readlink(cast_const_char n, cast_char buf, size)); } while (r == size); @@ -393,7 +393,7 @@ void file_func(struct connection *c) head = stracpy(cast_uchar "\r\nContent-Type: text/html\r\n"); } else { free(name); - if (stt.st_size < 0 || stt.st_size > MAXINT) { + if (stt.st_size < 0 || stt.st_size > INT_MAX) { EINTRLOOP(rs, close(h)); setcstate(c, S_LARGE_FILE); abort_connection(c); return; diff --git a/gif.c b/gif.c @@ -67,7 +67,7 @@ static void alloc_color_map(int colors) struct gif_decoder* deco=global_cimg->decoder; free(deco->color_map); - if ((unsigned)colors > MAXINT / 3 / sizeof(*(deco->color_map))) overalloc(); + if ((unsigned)colors > INT_MAX / 3 / sizeof(*(deco->color_map))) overalloc(); deco->color_map = xmalloc(colors * 3 * sizeof(*(deco->color_map))); } @@ -444,7 +444,7 @@ gif_accept_byte(unsigned char c) return; /* Bad dimensions */ } 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(); + if ((unsigned)global_cimg->width * (unsigned)global_cimg->buffer_bytes_per_pixel > INT_MAX) overalloc(); deco->actual_line=global_cimg->strip_optimized ?xmalloc((size_t)global_cimg->width * global_cimg ->buffer_bytes_per_pixel) diff --git a/html.c b/html.c @@ -105,7 +105,7 @@ int parse_element(unsigned char *e, unsigned char *eof, unsigned char **name, in #define add_chr(s, l, c) \ do { \ if (!((l) & (32 - 1))) { \ - if ((unsigned)(l) > MAXINT - 32) overalloc(); \ + if ((unsigned)(l) > INT_MAX - 32) overalloc(); \ (s) = xrealloc((s), (l) + 32); \ } \ (s)[(l)++] = (c); \ @@ -1880,7 +1880,7 @@ static void html_input(unsigned char *a) set_max_textarea_width(&size); } fc->size = size; - if ((fc->maxlength = get_num(a, cast_uchar "maxlength")) == -1) fc->maxlength = MAXINT / 4; + if ((fc->maxlength = get_num(a, cast_uchar "maxlength")) == -1) fc->maxlength = INT_MAX / 4; if (fc->type == FC_CHECKBOX || fc->type == FC_RADIO) fc->default_state = has_attr(a, cast_uchar "checked"); fc->ro = has_attr(a, cast_uchar "disabled") ? 2 : has_attr(a, cast_uchar "readonly") ? 1 : 0; if (fc->type == FC_IMAGE) { @@ -2065,7 +2065,7 @@ static void new_menu_item(unsigned char *name, long data, int fullname) if (menu_stack_size && name) { top = item = menu_stack[menu_stack_size - 1]; while (item->text) item++; - if ((size_t)((unsigned char *)(item + 2) - (unsigned char *)top) > MAXINT) + if ((size_t)((unsigned char *)(item + 2) - (unsigned char *)top) > INT_MAX) overalloc(); top = xrealloc(top, (unsigned char *)(item + 2) - (unsigned char *)top); @@ -2089,7 +2089,7 @@ static void new_menu_item(unsigned char *name, long data, int fullname) } else free(name); if (name && data == -1) { - if ((unsigned)menu_stack_size > MAXINT / sizeof(struct menu_item *) - 1) + if ((unsigned)menu_stack_size > INT_MAX / sizeof(struct menu_item *) - 1) overalloc(); menu_stack = xrealloc(menu_stack, (menu_stack_size + 1) * sizeof(struct menu_item *)); menu_stack[menu_stack_size++] = nmenu; @@ -2288,7 +2288,7 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha if (preselect == -1 && has_attr(t_attr, cast_uchar "selected")) preselect = order; v = get_exact_attr_val(t_attr, cast_uchar "value"); if (!(order & (ALLOC_GR - 1))) { - if ((unsigned)order > MAXINT / sizeof(unsigned char *) - ALLOC_GR) + if ((unsigned)order > INT_MAX / sizeof(unsigned char *) - ALLOC_GR) overalloc(); val = xrealloc(val, (order + ALLOC_GR) * sizeof(unsigned char *)); @@ -2338,7 +2338,7 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha *end = en; if (!order) goto abort; fc = mem_calloc(sizeof(struct form_control)); - if ((unsigned)order > (unsigned)MAXINT / sizeof(unsigned char *)) + if ((unsigned)order > (unsigned)INT_MAX / sizeof(unsigned char *)) overalloc(); lbls = mem_calloc(order * sizeof(unsigned char *)); fc->form_num = last_form_tag ? (int)(last_form_tag - startf) : 0; @@ -2438,7 +2438,7 @@ static void do_html_textarea(unsigned char *attr, unsigned char *html, unsigned else if (!casestrcmp(w, cast_uchar "off")) fc->wrap = 0; free(w); } - if ((fc->maxlength = get_num(attr, cast_uchar "maxlength")) == -1) fc->maxlength = MAXINT / 4; + if ((fc->maxlength = get_num(attr, cast_uchar "maxlength")) == -1) fc->maxlength = INT_MAX / 4; if (rows > 1) ln_break(1); else put_chrs(cast_uchar " ", 1); html_stack_dup(); @@ -2536,7 +2536,7 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int if (*a == '%') q = q * ww / 100; else if (*a != '*') q = (q + (www - 1) / 2) / (www ? www : 1); else if (!(q = -q)) q = -1; - if ((unsigned)ol > MAXINT / sizeof(int) - 1) + if ((unsigned)ol > INT_MAX / sizeof(int) - 1) overalloc(); o = xrealloc(o, (ol + 1) * sizeof(int)); o[ol++] = q; @@ -2586,7 +2586,7 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int int nn = 0; for (i = 0; i < ol; i++) if (o[i] < 0) nn = 1; if (!nn) goto distribute; - if ((unsigned)ol > MAXINT / sizeof(int)) + if ((unsigned)ol > INT_MAX / sizeof(int)) overalloc(); oo = xmalloc(ol * sizeof(int)); memcpy(oo, o, ol * sizeof(int)); @@ -2685,7 +2685,7 @@ static void html_frameset(unsigned char *a) continue; } if ((w = parse_width(d, 1)) != -1) { - if ((unsigned)fp->n > (MAXINT - sizeof(struct frameset_param)) / sizeof(int) - 1) + if ((unsigned)fp->n > (INT_MAX - sizeof(struct frameset_param)) / sizeof(int) - 1) overalloc(); fp = xrealloc(fp, sizeof(struct frameset_param) + (fp->n + 1) * sizeof(int)); @@ -3434,7 +3434,7 @@ int get_image_map(unsigned char *head, unsigned char *s, unsigned char *eof, uns && !xstrcmp(ll->onclick, ld->onclick)) goto se2; } - if ((unsigned)nmenu > MAXINT / sizeof(struct menu_item) - 2) + if ((unsigned)nmenu > INT_MAX / sizeof(struct menu_item) - 2) overalloc(); nm = xrealloc(*menu, (nmenu + 2) * sizeof(struct menu_item)); *menu = nm; diff --git a/html_gr.c b/html_gr.c @@ -191,7 +191,7 @@ void flush_pending_line_to_obj(struct g_part *p, int minheight) p->cy = safe_add(p->cy, w); a->go.yw = p->cy; if (!(a->n_lines & (a->n_lines + 1))) { - if ((unsigned)a->n_lines > ((MAXINT - sizeof(struct g_object_area)) / sizeof(struct g_object_text *) - 1) / 2) + if ((unsigned)a->n_lines > ((INT_MAX - sizeof(struct g_object_area)) / sizeof(struct g_object_text *) - 1) / 2) overalloc(); a = xrealloc(a, sizeof(struct g_object_area) + sizeof(struct g_object_text *) @@ -232,7 +232,7 @@ void add_object_to_line(struct g_part *pp, struct g_object_line **lp, struct g_o if (!go) return; (*lp)->n_entries++; - if ((unsigned)(*lp)->n_entries > (MAXINT - sizeof(struct g_object_line)) / sizeof(struct g_object *)) + if ((unsigned)(*lp)->n_entries > (INT_MAX - sizeof(struct g_object_line)) / sizeof(struct g_object *)) overalloc(); l = xrealloc(*lp, sizeof(struct g_object_line) + sizeof(struct g_object *) @@ -281,7 +281,7 @@ static void split_line_object(struct g_part *p, struct g_object *text_go, unsign return; } sl = strlen(cast_const_char ptr); - if (sl > MAXINT - sizeof(struct g_object_text)) + if (sl > INT_MAX - sizeof(struct g_object_text)) overalloc(); t2 = mem_calloc(sizeof(struct g_object_text) + sl); t2->goti.go.mouse_event = g_text_mouse; @@ -554,7 +554,7 @@ static void do_image(struct g_part *p, struct image_description *im) !casestrcmp(ld->shape, cast_uchar "polygon") ? SHAPE_POLY : -1; if (shape == -1) continue; - if ((unsigned)map->n_areas > (MAXINT - sizeof(struct image_map)) / sizeof(struct map_area) - 1) + if ((unsigned)map->n_areas > (INT_MAX - sizeof(struct image_map)) / sizeof(struct map_area) - 1) overalloc(); map = xrealloc(map, sizeof(struct image_map) + (map->n_areas + 1) @@ -586,7 +586,7 @@ static void do_image(struct g_part *p, struct image_description *im) p++; } else num = num * d_opt->image_scale / 100; - if ((unsigned)a->ncoords > MAXINT / sizeof(int) - 1) + if ((unsigned)a->ncoords > INT_MAX / sizeof(int) - 1) overalloc(); a->coords = xrealloc(a->coords, (a->ncoords + 1) * sizeof(int)); @@ -664,7 +664,7 @@ static void *g_html_special(void *p_, int c, ...) va_end(l); /* not needed to convert %AB here because html_tag will be called anyway */ sl = strlen(cast_const_char t); - if (sl > MAXINT - sizeof(struct g_object_tag)) + if (sl > INT_MAX - sizeof(struct g_object_tag)) overalloc(); tag = mem_calloc(sizeof(struct g_object_tag) + sl); tag->go.mouse_event = g_dummy_mouse; @@ -852,8 +852,8 @@ static void g_put_chars(void *p_, unsigned char *s, int l) safe_add(safe_add(ptl, l), ALLOC_GR); if (((ptl + ALLOC_GR - 1) & ~(ALLOC_GR - 1)) != ((ptl + l + ALLOC_GR - 1) & ~(ALLOC_GR - 1))) a1: { struct g_object_text *t; - if ((unsigned)l > MAXINT - || (unsigned)ptl + (unsigned)l > MAXINT - ALLOC_GR) + if ((unsigned)l > INT_MAX + || (unsigned)ptl + (unsigned)l > INT_MAX - ALLOC_GR) overalloc(); t = xrealloc(p->text, sizeof(struct g_object_text) + ((ptl + l + ALLOC_GR - 1) & ~(ALLOC_GR - 1))); diff --git a/html_r.c b/html_r.c @@ -63,7 +63,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(); + if ((unsigned)fd->n > INT_MAX / sizeof(struct frame_desc)) overalloc(); 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++) { @@ -247,7 +247,7 @@ static void xpand_lines(struct part *p, int y) if ((y ^ p->data->y) > p->data->y) { unsigned s; for (s = 1; s < (unsigned)y; s = s * 2 + 1) { - if (s > MAXINT / sizeof(struct line)) + if (s > INT_MAX / sizeof(struct line)) overalloc(); } p->data->data = xrealloc(p->data->data, @@ -280,7 +280,7 @@ static void xpand_line(struct part *p, int y, int x) if (x >= ln->allocated) { if (x >= 0x4000) ln->allocated = safe_add(x, x); else ln->allocated = safe_add(x, 0x10) & ~0xf; - if ((unsigned)ln->allocated > MAXINT / sizeof(chr)) + if ((unsigned)ln->allocated > INT_MAX / sizeof(chr)) overalloc(); ln->d = xrealloc(ln->d, ln->allocated*sizeof(chr)); } @@ -295,7 +295,7 @@ static void xpand_line(struct part *p, int y, int x) static void r_xpand_spaces(struct part *p, int l) { unsigned char *c; - if ((unsigned)l >= MAXINT) + if ((unsigned)l >= INT_MAX) overalloc(); c = xrealloc(p->spaces, l + 1); memset(c + p->spl, 0, l - p->spl + 1); @@ -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(); + if ((unsigned)l > INT_MAX / sizeof(chr)) overalloc(); a = xmalloc(l * sizeof(chr)); memcpy(a, &POS(0, y), l * sizeof(chr)); set_hchars(p, 0, y, s, ' ', p->attribute); @@ -539,15 +539,15 @@ struct link *new_link(struct f_data *f) if (!f) return NULL; if (!(f->nlinks & (ALLOC_GR - 1))) { - if ((unsigned)f->nlinks > MAXINT / sizeof(struct link) - ALLOC_GR) + if ((unsigned)f->nlinks > INT_MAX / sizeof(struct link) - ALLOC_GR) overalloc(); f->links = xrealloc(f->links, (f->nlinks + ALLOC_GR) * sizeof(struct link)); } memset(&f->links[f->nlinks], 0, sizeof(struct link)); #ifdef G - f->links[f->nlinks].r.x1 = MAXINT; - f->links[f->nlinks].r.y1 = MAXINT; + f->links[f->nlinks].r.x1 = INT_MAX; + f->links[f->nlinks].r.y1 = INT_MAX; #endif return &f->links[f->nlinks++]; } @@ -563,7 +563,7 @@ void html_tag(struct f_data *f, unsigned char *t, int x, int y) ll = 0; 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(); + if (sl > INT_MAX - sizeof(struct tag)) overalloc(); tag = xmalloc(sizeof(struct tag) + sl); tag->x = x; tag->y = y; @@ -639,7 +639,7 @@ static void put_chars(void *p_, unsigned char *c, int l) bad_utf: p->utf8_part_len = 0; if (!l) return; - if ((unsigned)l > (unsigned)MAXINT / sizeof(char_t)) overalloc(); + if ((unsigned)l > (unsigned)INT_MAX / sizeof(char_t)) overalloc(); uni_c = xmalloc(l * sizeof(char_t)); ll = 0; cc = c; @@ -789,7 +789,7 @@ static void put_chars(void *p_, unsigned char *c, int l) link->sel_color = get_attribute(fg, bg); link->n = 0; set_link: - if ((unsigned)link->n + (unsigned)ll > MAXINT / sizeof(struct point)) + if ((unsigned)link->n + (unsigned)ll > INT_MAX / sizeof(struct point)) overalloc(); pt = xrealloc(link->pos, (link->n + ll) * sizeof(struct point)); link->pos = pt; @@ -902,7 +902,7 @@ struct frameset_desc *create_frameset(struct f_data *fda, struct frameset_param return NULL; } if (fp->x && (unsigned)fp->x * (unsigned)fp->y / (unsigned)fp->x != (unsigned)fp->y) overalloc(); - if ((unsigned)fp->x * (unsigned)fp->y > (MAXINT - sizeof(struct frameset_desc)) / sizeof(struct frame_desc)) overalloc(); + if ((unsigned)fp->x * (unsigned)fp->y > (INT_MAX - sizeof(struct frameset_desc)) / sizeof(struct frame_desc)) overalloc(); fd = mem_calloc(sizeof(struct frameset_desc) + fp->x * fp->y * sizeof(struct frame_desc)); fd->n = fp->x * fp->y; fd->x = fp->x; @@ -1042,7 +1042,7 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig n = xmalloc(sizeof(struct node)); n->x = xs; n->y = ys; - n->xw = !table_level ? MAXINT - 1 : width; + n->xw = !table_level ? INT_MAX - 1 : width; add_to_list(data->nodes, n); } last_link_to_move = data ? data->nlinks : 0; @@ -1356,8 +1356,8 @@ static int sort_srch(struct f_data *f) { int i; int *min, *max; - if ((unsigned)f->y > MAXINT / sizeof(struct search *)) overalloc(); - if ((unsigned)f->y > MAXINT / sizeof(int)) overalloc(); + if ((unsigned)f->y > INT_MAX / sizeof(struct search *)) overalloc(); + if ((unsigned)f->y > INT_MAX / sizeof(int)) overalloc(); f->slines1 = xmalloc(f->y * sizeof(int)); f->slines2 = xmalloc(f->y * sizeof(int)); min = xmalloc(f->y * sizeof(int)); @@ -1374,7 +1374,7 @@ static int sort_srch(struct f_data *f) for (i = 0; i < f->y; i++) f->slines1[i] = f->slines2[i] = -1; for (i = 0; i < f->y; i++) { - min[i] = MAXINT; + min[i] = INT_MAX; max[i] = 0; } for (i = 0; i < f->nsearch_pos; i++) { @@ -1424,7 +1424,7 @@ static int add_srch_chr(struct f_data *f, unsigned c, int x, int y, int nn) } srch_last_chr = c; if (f->search_chr) f->search_chr[n_chr] = c; - if (n_chr == MAXINT) return -1; + if (n_chr == INT_MAX) return -1; n_chr++; if (srch_cont < 0xffff && x == srch_last_x + 1 && y == srch_last_y && nn == 1) { srch_cont++; @@ -1441,7 +1441,7 @@ static int add_srch_chr(struct f_data *f, unsigned c, int x, int y, int nn) f->search_pos[n_pos].co = 1; } srch_cont = 1; - if (n_pos == MAXINT) return -1; + if (n_pos == INT_MAX) return -1; n_pos++; } if (nn == 1) { diff --git a/html_tbl.c b/html_tbl.c @@ -300,15 +300,15 @@ static struct table_cell *new_cell(struct table *t, int x, int y) nt.rx = t->rx; nt.ry = t->ry; while (x >= nt.rx) { - if ((unsigned)nt.rx > MAXINT / 2) overalloc(); + if ((unsigned)nt.rx > INT_MAX / 2) overalloc(); nt.rx *= 2; } while (y >= nt.ry) { - if ((unsigned)nt.ry > MAXINT / 2) overalloc(); + if ((unsigned)nt.ry > INT_MAX / 2) overalloc(); nt.ry *= 2; } if ((unsigned)nt.rx * (unsigned)nt.ry / (unsigned)nt.rx != (unsigned)nt.ry) overalloc(); - if ((unsigned)nt.rx * (unsigned)nt.ry > MAXINT / sizeof(struct table_cell)) overalloc(); + if ((unsigned)nt.rx * (unsigned)nt.ry > INT_MAX / sizeof(struct table_cell)) overalloc(); nt.cells = mem_calloc(nt.rx * nt.ry * sizeof(struct table_cell)); for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) @@ -329,10 +329,10 @@ static void new_columns(struct table *t, int span, int width, int align, int val int n = t->rc; struct table_column *nc; while (t->c + span > n) { - if ((unsigned)n > MAXINT / 2) overalloc(); + if ((unsigned)n > INT_MAX / 2) overalloc(); n *= 2; } - if ((unsigned)n > MAXINT / sizeof(struct table_column)) + if ((unsigned)n > INT_MAX / sizeof(struct table_column)) overalloc(); nc = xrealloc(t->cols, n * sizeof(struct table_column)); t->rc = n; @@ -354,10 +354,10 @@ static void set_td_width(struct table *t, int x, int width, int f) int i; int *nc; while (x >= n) { - if ((unsigned)n > MAXINT / 2) overalloc(); + if ((unsigned)n > INT_MAX / 2) overalloc(); n *= 2; } - if ((unsigned)n > MAXINT / sizeof(int)) + if ((unsigned)n > INT_MAX / sizeof(int)) overalloc(); nc = xrealloc(t->xcols, n * sizeof(int)); for (i = t->xc; i < n; i++) @@ -435,7 +435,7 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign html = en; if (bad_html && !p && !lbhp) { if (!(*bhp & (ALLOC_GR-1))) { - if ((unsigned)*bhp > MAXINT / sizeof(struct s_e) - ALLOC_GR) + if ((unsigned)*bhp > INT_MAX / sizeof(struct s_e) - ALLOC_GR) overalloc(); *bad_html = xrealloc(*bad_html, (*bhp + ALLOC_GR) * sizeof(struct s_e)); @@ -682,7 +682,7 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign } } - if ((unsigned)t->y > MAXINT / sizeof(int)) overalloc(); + if ((unsigned)t->y > INT_MAX / sizeof(int)) overalloc(); t->r_heights = mem_calloc(t->y * sizeof(int)); for (x = 0; x < t->c; x++) if (t->cols[x].width != W_AUTO) set_td_width(t, x, t->cols[x].width, 1); @@ -863,7 +863,7 @@ static int g_get_hline_pad(struct table *t, int row, int *plpos, int *plsize) static int get_column_widths(struct table *t) { int i, j, s, ns; - if ((unsigned)t->x > MAXINT / sizeof(int)) overalloc(); + if ((unsigned)t->x > INT_MAX / sizeof(int)) overalloc(); if (!t->min_c) t->min_c = xmalloc(t->x * sizeof(int)); if (!t->max_c) @@ -874,7 +874,7 @@ static int get_column_widths(struct table *t) memset(t->max_c, 0, t->x * sizeof(int)); s = 1; do { - ns = MAXINT; + ns = INT_MAX; for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) { struct table_cell *c = CELL(t, i, j); if (c->spanned || !c->used) continue; @@ -904,7 +904,7 @@ static int get_column_widths(struct table *t) for (k = 0; k < s; k++) if (t->min_c[i + k] > t->max_c[i + k]) t->max_c[i + k] = t->min_c[i + k]; } else if (c->colspan > s && c->colspan < ns) ns = c->colspan; } - } while ((s = ns) != MAXINT); + } while ((s = ns) != INT_MAX); return 0; } @@ -961,7 +961,7 @@ static void distribute_widths(struct table *t, int width) for (i = 0; i < t->x; i++) if (t->max_c[i] > mmax_c) mmax_c = t->max_c[i]; memcpy(t->w_c, t->min_c, t->x * sizeof(int)); t->rw = width; - if ((unsigned)t->x > MAXINT / sizeof(int)) overalloc(); + if ((unsigned)t->x > INT_MAX / sizeof(int)) overalloc(); u = xmalloc(t->x); w = xmalloc(t->x * sizeof(int)); mx = xmalloc(t->x * sizeof(int)); @@ -1008,12 +1008,12 @@ static void distribute_widths(struct table *t, int width) case 5: if (t->xcols[i] < 0) { w[i] = t->xcols[i] <= -2 ? -2 - t->xcols[i] : 1; - mx[i] = MAXINT; + mx[i] = INT_MAX; } break; case 6: w[i] = 1; - mx[i] = MAXINT; + mx[i] = INT_MAX; break; default: /*internal("could not expand table");*/ @@ -1070,7 +1070,7 @@ static void check_table_widths(struct table *t) int i, j; int s, ns; int m, mi = 0; /* go away, warning! */ - if ((unsigned)t->x > MAXINT / sizeof(int)) overalloc(); + if ((unsigned)t->x > INT_MAX / sizeof(int)) overalloc(); w = mem_calloc(t->x * sizeof(int)); for (j = 0; j < t->y; j++) for (i = 0; i < t->x; i++) { struct table_cell *c = CELL(t, i, j); @@ -1089,7 +1089,7 @@ static void check_table_widths(struct table *t) } s = 1; do { - ns = MAXINT; + ns = INT_MAX; for (i = 0; i < t->x; i++) for (j = 0; j < t->y; j++) { struct table_cell *c = CELL(t, i, j); if (!c->start) continue; @@ -1115,7 +1115,7 @@ static void check_table_widths(struct table *t) }*/ } else if (c->colspan > s && c->colspan < ns) ns = c->colspan; } - } while ((s = ns) != MAXINT); + } while ((s = ns) != INT_MAX); s = 0; ns = 0; for (i = 0; i < t->x; i++) { @@ -1205,7 +1205,7 @@ static void get_table_heights(struct table *t) } s = 1; do { - ns = MAXINT; + ns = INT_MAX; for (j = 0; j < t->y; j++) { for (i = 0; i < t->x; i++) { struct table_cell *cell = CELL(t, i, j); @@ -1228,7 +1228,7 @@ static void get_table_heights(struct table *t) } else if (cell->rowspan > s && cell->rowspan < ns) ns = cell->rowspan; } } - } while ((s = ns) != MAXINT); + } while ((s = ns) != INT_MAX); if (!F) { t->rh = (!!(t->frame & F_ABOVE) + !!(t->frame & F_BELOW)) * !!t->border; for (j = 0; j < t->y; j++) { @@ -1384,10 +1384,10 @@ static void display_table_frames(struct table *t, int x, int y) short *fh, *fv; int i, j; int cx, cy; - if ((unsigned)t->x > MAXINT) overalloc(); - if ((unsigned)t->y > MAXINT) overalloc(); + if ((unsigned)t->x > INT_MAX) overalloc(); + if ((unsigned)t->y > INT_MAX) 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(); + if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > INT_MAX) overalloc(); 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); @@ -1663,7 +1663,7 @@ static void add_to_rect_sets(struct rect_set ***s, int *n, struct rect *r) for (i = r->y1 >> RECT_BOUND_BITS; i <= (r->y2 - 1) >> RECT_BOUND_BITS; i++) { if (i >= *n) { struct rect_set **ns; - if ((unsigned)i > MAXINT / sizeof(struct rect_set *) - 1) + if ((unsigned)i > INT_MAX / sizeof(struct rect_set *) - 1) overalloc(); ns = xrealloc(*s, (i + 1) * sizeof(struct rect_set *)); @@ -1685,8 +1685,8 @@ static void add_to_cell_sets(struct table_cell ****s, int **nn, int *n, struct r if (i >= *n) { struct table_cell ***ns; int *nnn; - if ((unsigned)i > MAXINT / sizeof(struct table_cell ***) - 1 - || (unsigned)i > MAXINT / sizeof(int *) - 1) + if ((unsigned)i > INT_MAX / sizeof(struct table_cell ***) - 1 + || (unsigned)i > INT_MAX / sizeof(int *) - 1) overalloc(); ns = xrealloc(*s, (i + 1) * sizeof(struct table_cell **)); @@ -1701,7 +1701,7 @@ static void add_to_cell_sets(struct table_cell ****s, int **nn, int *n, struct r } { struct table_cell **nc; - if ((unsigned)(*nn)[i] > MAXINT / sizeof(struct table_cell *) - 1) + if ((unsigned)(*nn)[i] > INT_MAX / sizeof(struct table_cell *) - 1) overalloc(); nc = xrealloc((*s)[i], ((*nn)[i] + 1) * sizeof(struct table_cell *)); @@ -1865,10 +1865,10 @@ static void process_g_table(struct g_part *gp, struct table *t) } } - if ((unsigned)t->x > MAXINT) overalloc(); - if ((unsigned)t->y > MAXINT) overalloc(); + if ((unsigned)t->x > INT_MAX) overalloc(); + if ((unsigned)t->y > INT_MAX) 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(); + if (((unsigned)t->x + 2) * ((unsigned)t->y + 2) > INT_MAX) overalloc(); 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); @@ -1989,7 +1989,7 @@ static void process_g_table(struct g_part *gp, struct table *t) struct g_object_tag *tag; size_t sl; sl = strlen(cast_const_char c->tag); - if (sl > MAXINT - sizeof(struct g_object_tag)) overalloc(); + if (sl > INT_MAX - sizeof(struct g_object_tag)) overalloc(); tag = mem_calloc(sizeof(struct g_object_tag) + sl); tag->go.mouse_event = g_dummy_mouse; tag->go.draw = g_dummy_draw; diff --git a/http.c b/http.c @@ -100,7 +100,7 @@ a: lp = 0; while (y[lp] >= ' ' && y[lp] != u) { lp++; - if (lp == MAXINT) + if (lp == INT_MAX) overalloc(); } return memacpy(y, lp); @@ -720,7 +720,7 @@ next_chunk: long n = 0; if (l != -1) n = strtol((char *)rb->data, (char **)(void *)&de, 16); - if (l == -1 || n < 0 || n >= MAXINT || de == rb->data) { + if (l == -1 || n < 0 || n >= INT_MAX || de == rb->data) { setcstate(c, S_HTTP_ERROR); abort_connection(c); return; diff --git a/https.c b/https.c @@ -335,7 +335,7 @@ static void set_session_cache_entry(SSL_CTX *ctx, unsigned char *host, int port, if (!s) return; sl = strlen(cast_const_char host); - if (sl > MAXINT - sizeof(sizeof(struct session_cache_entry))) return; + if (sl > INT_MAX - sizeof(sizeof(struct session_cache_entry))) return; sce = xmalloc(sizeof(struct session_cache_entry) + sl); sce->absolute_time = get_absolute_time(); sce->ctx = ctx; diff --git a/img.c b/img.c @@ -27,7 +27,7 @@ static int is_image_size_sane(int x, int y) unsigned a = (unsigned)x * (unsigned)y * 6; if (y && a / (unsigned)y / 6 != (unsigned)x) return 0; - return a < MAXINT; + return a < INT_MAX; } static void destroy_decoder (struct cached_image *cimg) @@ -283,7 +283,7 @@ int header_dimensions_known(struct cached_image *cimg) cimg->dregs = NULL; goto skip_img; } - if ((unsigned)cimg->width > MAXINT / sizeof(*buf_16) / 3) overalloc(); + if ((unsigned)cimg->width > INT_MAX / sizeof(*buf_16) / 3) overalloc(); buf_16 = xmalloc(sizeof(*buf_16) * 3 * cimg->width); round_color_sRGB_to_48(&red, &green, &blue , cimg->background_color); @@ -325,7 +325,7 @@ int header_dimensions_known(struct cached_image *cimg) cimg->rows_added=1; 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(); + if ((unsigned)cimg->width * (unsigned)cimg->height > (unsigned)INT_MAX / cimg->buffer_bytes_per_pixel) overalloc(); cimg->buffer = xmalloc((size_t)cimg->width * (size_t)cimg->height * (size_t)cimg->buffer_bytes_per_pixel); if (!cimg->buffer) return 1; @@ -505,7 +505,7 @@ void buffer_to_bitmap_incremental(struct cached_image *cimg buffer_to_bitmap_incremental"); } #endif /* #ifdef DEBUG */ - if ((unsigned)cimg->width > MAXINT / max_height / 3 / sizeof(*tmp)) overalloc(); + if ((unsigned)cimg->width > INT_MAX / max_height / 3 / sizeof(*tmp)) overalloc(); tmp = xmalloc(cimg->width*(height<max_height?height:max_height)*3*sizeof(*tmp)); /* Prepare a fake bitmap for dithering */ tmpbmp.x=cimg->width; @@ -587,7 +587,7 @@ buffer_to_bitmap"); else{ 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(); + if ((unsigned)ix * (unsigned)iy > INT_MAX / sizeof(*tmp) / 3) overalloc(); tmp = xmalloc(ix*iy*3*sizeof(*tmp)); if (tmp) buffer_to_16(tmp,cimg,cimg->buffer,iy); if (!cimg->decoder) { @@ -617,7 +617,7 @@ buffer_to_bitmap"); } if (gonna_be_smart){ if (dither_images) { - if ((unsigned)cimg->width > MAXINT / 3 / sizeof(*dregs)) overalloc(); + if ((unsigned)cimg->width > INT_MAX / 3 / sizeof(*dregs)) overalloc(); dregs = mem_calloc(sizeof(*dregs)*3*cimg->width); } else { dregs = NULL; diff --git a/jpeg.c b/jpeg.c @@ -211,7 +211,7 @@ void jpeg_restart(struct cached_image *cimg, unsigned char *data, int length) * chunks are so small the decoder can't move on on a single chunk * so it has to accumulate more chunks together. This is why the buffer * is there. */ - if ((unsigned)global_cinfo->src->bytes_in_buffer + (unsigned)length > MAXINT) overalloc(); + if ((unsigned)global_cinfo->src->bytes_in_buffer + (unsigned)length > INT_MAX) overalloc(); if ((unsigned)global_cinfo->src->bytes_in_buffer + (unsigned)length < (unsigned)length) overalloc(); if (deco->jdata){ /* If there is already some decoder buffer, we have to diff --git a/kbd.c b/kbd.c @@ -104,7 +104,7 @@ retry: } } if (w < len) { - if ((unsigned)itrm->eqlen + (unsigned)(len - w) > MAXINT) + if ((unsigned)itrm->eqlen + (unsigned)(len - w) > INT_MAX) overalloc(); itrm->ev_queue = xrealloc(itrm->ev_queue, itrm->eqlen + len - w); memcpy(itrm->ev_queue + itrm->eqlen, data + w, len - w); diff --git a/links.h b/links.h @@ -2033,9 +2033,9 @@ struct background { struct f_data_c; -#define G_OBJ_ALIGN_SPECIAL (MAXINT - 2) -#define G_OBJ_ALIGN_MIDDLE (MAXINT - 2) -#define G_OBJ_ALIGN_TOP (MAXINT - 1) +#define G_OBJ_ALIGN_SPECIAL (INT_MAX - 2) +#define G_OBJ_ALIGN_MIDDLE (INT_MAX - 2) +#define G_OBJ_ALIGN_TOP (INT_MAX - 1) struct g_object { /* public data --- must be same in all g_object* structures */ diff --git a/main.c b/main.c @@ -283,8 +283,8 @@ static void end_dump(struct object_request *r, void *p) off_t l; int w; l = frag->length - (dump_pos - frag->offset); - if (l >= MAXINT) - l = MAXINT; + if (l >= INT_MAX) + l = INT_MAX; w = hard_write(1, frag->data + dump_pos - frag->offset, (int)l); if (w != l) { detach_object_connection(r, dump_pos); diff --git a/menu.c b/menu.c @@ -447,7 +447,7 @@ static void flush_caches(struct terminal *term, void *d, void *e) void go_backwards(struct terminal *term, void *id_ptr, void *ses_) { struct session *ses = (struct session *)ses_; - unsigned want_id = (int)(long)id_ptr; + unsigned want_id = (unsigned)(long)id_ptr; struct location *l; struct list_head *ll; int n = 0; @@ -484,7 +484,7 @@ static void add_history_menu_entry(struct terminal *term, struct menu_item **mi, add_to_menu(mi, url, cast_uchar "", cast_uchar "", go_backwards, (void *)(long)l->location_id, 0, *n); (*n)++; - if (*n == MAXINT) + if (*n == INT_MAX) overalloc(); } @@ -2058,7 +2058,7 @@ static void cache_opt(struct terminal *term, void *xxx, void *yyy) d->items[a].data = mc_str; d->items[a].fn = check_number; d->items[a].gid = 0; - d->items[a].gnum = MAXINT / 1024; + d->items[a].gnum = INT_MAX / 1024; a++; #ifdef G if (F) @@ -2068,14 +2068,14 @@ static void cache_opt(struct terminal *term, void *xxx, void *yyy) d->items[a].data = ic_str; d->items[a].fn = check_number; d->items[a].gid = 0; - d->items[a].gnum = MAXINT / 1024; + d->items[a].gnum = INT_MAX / 1024; a++; d->items[a].type = D_FIELD; d->items[a].dlen = 8; d->items[a].data = fc_str; d->items[a].fn = check_number; d->items[a].gid = 0; - d->items[a].gnum = MAXINT / 1024; + d->items[a].gnum = INT_MAX / 1024; a++; } #endif diff --git a/os_dep.c b/os_dep.c @@ -523,7 +523,7 @@ struct open_in_new *get_open_in_new(int environment) environment = ENV_G; for (i = 0; i < (int)array_elements(oinw); i++) if ((environment & oinw[i].env) == oinw[i].env) { - if ((unsigned)noin > MAXINT / sizeof(struct open_in_new) - 2) + if ((unsigned)noin > INT_MAX / sizeof(struct open_in_new) - 2) overalloc(); oin = xrealloc(oin, (noin + 2) * sizeof(struct open_in_new)); oin[noin].text = oinw[i].text; diff --git a/sched.c b/sched.c @@ -1077,7 +1077,7 @@ void add_blacklist_entry(unsigned char *host, int flags) return; } sl = strlen((const char *)host); - if (sl > MAXINT - sizeof(struct blacklist_entry)) + if (sl > INT_MAX - sizeof(struct blacklist_entry)) overalloc(); b = xmalloc(sizeof(struct blacklist_entry) + sl); b->flags = flags; diff --git a/select.c b/select.c @@ -553,7 +553,7 @@ void set_handlers_file_line(int fd, void (*read_func)(void *), void (*write_func return; } if (fd >= n_threads) { - if ((unsigned)fd > (unsigned)MAXINT / sizeof(struct thread) - 1) + if ((unsigned)fd > (unsigned)INT_MAX / sizeof(struct thread) - 1) overalloc(); threads = xrealloc(threads, (fd + 1) * sizeof(struct thread)); memset(threads + n_threads, 0, (fd + 1 - n_threads) * sizeof(struct thread)); @@ -881,7 +881,7 @@ void select_loop(void (*init)(void)) if (tt < 1000) #endif { - tv.tv_sec = tt / 1000 < MAXINT ? (int)(tt / 1000) : MAXINT; + tv.tv_sec = tt / 1000 < INT_MAX ? (int)(tt / 1000) : INT_MAX; tv.tv_usec = (tt % 1000) * 1000; tm = &tv; } diff --git a/session.c b/session.c @@ -139,7 +139,7 @@ unsigned char *get_err_msg(int state) 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(); + if (sl > INT_MAX - sizeof(struct strerror_val)) overalloc(); s = xmalloc(sizeof(struct strerror_val) + sl); strcpy(cast_char s->msg, cast_const_char e); add_to_list(strerror_buf, s); @@ -855,7 +855,7 @@ static int download_write(struct download *down, void *ptr, off_t to_write) { int w; int err; - if (to_write != (int)to_write || (int)to_write < 0) to_write = MAXINT; + if (to_write != (int)to_write || (int)to_write < 0) to_write = INT_MAX; try_write_again: w = hard_write(down->handle, ptr, (int)to_write); if (w >= 0) err = 0; @@ -1636,8 +1636,8 @@ static void html_interpret(struct f_data_c *fd, int report_status) if (o.plain == 1 && !o.break_long_lines) { o.xp = 0; o.yp = 0; - o.xw = MAXINT; - o.yw = MAXINT; + o.xw = INT_MAX; + o.yw = INT_MAX; } else { o.xp = fd->xp; o.yp = fd->yp; @@ -1723,7 +1723,7 @@ struct additional_file *request_additional_file(struct f_data *f, unsigned char return af; } sl = strlen(cast_const_char url); - if (sl > MAXINT - sizeof(struct additional_file)) overalloc(); + if (sl > INT_MAX - sizeof(struct additional_file)) overalloc(); af = xmalloc(sizeof(struct additional_file) + sl); af->use_tag = 0; af->use_tag2 = 0; @@ -1752,7 +1752,7 @@ static void copy_additional_files(struct additional_files **a) 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(); + if (sl > INT_MAX - sizeof(struct additional_file)) overalloc(); afc = xmalloc(sizeof(struct additional_file) + sl); memcpy(afc, af, sizeof(struct additional_file) + sl); if (af->rq) clone_object(af->rq, &afc->rq); @@ -2408,7 +2408,7 @@ static void type_query_multiple_programs(struct session *ses, unsigned char *ct, text_array[4] = !anonymous ? TEXT_(T_DO_YOU_WANT_TO_OPEN_SAVE_OR_DISPLAY_THIS_FILE) : TEXT_(T_DO_YOU_WANT_TO_OPEN_OR_DISPLAY_THIS_FILE); text_array[5] = NULL; - if ((unsigned)n > (MAXINT - sizeof(struct dialog)) / sizeof(struct dialog_item) - 4) overalloc(); + if ((unsigned)n > (INT_MAX - sizeof(struct dialog)) / sizeof(struct dialog_item) - 4) overalloc(); d = mem_calloc(sizeof(struct dialog) + (n + 2 + (!anonymous)) * sizeof(struct dialog_item)); d->title = TEXT_(T_WHAT_TO_DO); d->fn = msg_box_fn; @@ -2802,7 +2802,7 @@ void *create_session_info(int cp, unsigned char *url, unsigned char *framename, int l = (int)sl; int l1 = (int)sl1; unsigned char *i; - if (sl > MAXINT || sl1 > MAXINT) overalloc(); + if (sl > INT_MAX || sl1 > INT_MAX) overalloc(); if (framename && !strcmp(cast_const_char framename, "_blank")) l1 = 0; i = init_str(); @@ -2843,7 +2843,7 @@ static int read_session_info(struct session *ses, void *data, int len) if (sz1) { unsigned char *tgt; if (len<3*(int)sizeof(int)+sz+sz1) goto bla; - if ((unsigned)sz1 >= MAXINT) overalloc(); + if ((unsigned)sz1 >= INT_MAX) overalloc(); tgt = xmalloc(sz1 + 1); memcpy(tgt, (unsigned char*)((int*)data+3)+sz,sz1); tgt[sz1] = 0; @@ -2855,7 +2855,7 @@ static int read_session_info(struct session *ses, void *data, int len) if (sz) { unsigned char *u, *uu; if (len < 3 * (int)sizeof(int) + sz) return -1; - if ((unsigned)sz >= MAXINT) overalloc(); + if ((unsigned)sz >= INT_MAX) overalloc(); u = xmalloc(sz + 1); memcpy(u, (int *)data + 3, sz); u[sz] = 0; diff --git a/string.c b/string.c @@ -40,7 +40,7 @@ void add_to_strn(unsigned char **s, unsigned char *a) { unsigned char *p; size_t l1 = strlen(cast_const_char *s), l2 = strlen(cast_const_char a); - if (((l1 | l2) | (l1 + l2 + 1)) > MAXINT) + if (((l1 | l2) | (l1 + l2 + 1)) > INT_MAX) overalloc(); p = xrealloc(*s, l1 + l2 + 1); strcat(cast_char p, cast_const_char a); @@ -50,7 +50,7 @@ void add_to_strn(unsigned char **s, unsigned char *a) void extend_str(unsigned char **s, int n) { size_t l = strlen(cast_const_char *s); - if (((l | n) | (l + n + 1)) > MAXINT) + if (((l | n) | (l + n + 1)) > INT_MAX) overalloc(); *s = xrealloc(*s, l + n + 1); } @@ -67,7 +67,7 @@ void add_bytes_to_str(unsigned char **s, int *l, unsigned char *a, size_t ll) p = *s; old_length = (unsigned)*l; - if (ll + old_length >= (unsigned)MAXINT / 2 || ll + old_length < ll) overalloc(); + if (ll + old_length >= (unsigned)INT_MAX / 2 || ll + old_length < ll) overalloc(); new_length = old_length + ll; *l = (int)new_length; x = old_length ^ new_length; @@ -136,14 +136,14 @@ long strtolx(unsigned char *c, unsigned char **end) if (!*end) return l; if (upcase(**end) == 'K') { (*end)++; - if (l < -MAXINT / 1024) return -MAXINT; - if (l > MAXINT / 1024) return MAXINT; + if (l < -INT_MAX / 1024) return -INT_MAX; + if (l > INT_MAX / 1024) return INT_MAX; return l * 1024; } if (upcase(**end) == 'M') { (*end)++; - if (l < -MAXINT / (1024 * 1024)) return -MAXINT; - if (l > MAXINT / (1024 * 1024)) return MAXINT; + if (l < -INT_MAX / (1024 * 1024)) return -INT_MAX; + if (l > INT_MAX / (1024 * 1024)) return INT_MAX; return l * (1024 * 1024); } return l; diff --git a/terminal.c b/terminal.c @@ -53,7 +53,7 @@ unsigned char *get_cwd(void) if (gcr) return buf; free(buf); if (errno != ERANGE) break; - if ((unsigned)bufsize > MAXINT - 128) overalloc(); + if ((unsigned)bufsize > INT_MAX - 128) overalloc(); bufsize += 128; } return NULL; @@ -101,7 +101,7 @@ static void alloc_term_screen(struct terminal *term) if (term->y < 0) term->y = 1; if ((term->x && (unsigned)term->x * (unsigned)term->y / (unsigned)term->x != (unsigned)term->y) - || (unsigned)term->x * (unsigned)term->y > MAXINT / sizeof(*term->screen)) + || (unsigned)term->x * (unsigned)term->y > INT_MAX / sizeof(*term->screen)) overalloc(); s = xrealloc(term->screen, term->x * term->y * sizeof(*term->screen)); t = xrealloc(term->last_screen, @@ -251,7 +251,7 @@ void add_to_rect_set(struct rect_set **s, struct rect *r) if (i >= ss->m) ss->m = i + 1; return; } - if ((unsigned)ss->rl > (MAXINT - sizeof(struct rect_set)) / sizeof(struct rect) - R_GR) + if ((unsigned)ss->rl > (INT_MAX - sizeof(struct rect_set)) / sizeof(struct rect) - R_GR) overalloc(); ss = xrealloc(ss, sizeof(struct rect_set) + sizeof(struct rect) * (ss->rl + R_GR)); @@ -680,7 +680,7 @@ struct terminal *init_gfx_term(void (*root_window)(struct window *, struct links term->blocked = -1; term->x = dev->size.x2; term->y = dev->size.y2; - term->last_mouse_x = term->last_mouse_y = term->last_mouse_b = MAXINT; + term->last_mouse_x = term->last_mouse_y = term->last_mouse_b = INT_MAX; term->environment = !(drv->flags & GD_ONLY_1_WINDOW) ? ENV_G : 0; if (!casestrcmp(drv->name, cast_uchar "x")) term->environment |= ENV_XWIN; term->spec = &gfx_term; @@ -706,7 +706,7 @@ struct terminal *init_gfx_term(void (*root_window)(struct window *, struct links struct links_event ev = { EV_INIT, 0, 0, 0 }; ev.x = dev->size.x2; ev.y = dev->size.y2; - if ((unsigned)len > MAXINT - sizeof(int)) overalloc(); + if ((unsigned)len > INT_MAX - sizeof(int)) overalloc(); ptr = xmalloc(sizeof(int) + len); *ptr = len; memcpy(ptr + 1, info, len); @@ -786,7 +786,7 @@ void t_mouse(struct graphics_device *dev, int x, int y, int b) term->last_mouse_y = y; term->last_mouse_b = b; } else { - term->last_mouse_x = term->last_mouse_y = term->last_mouse_b = MAXINT; + term->last_mouse_x = term->last_mouse_y = term->last_mouse_b = INT_MAX; } r.x2 = dev->size.x2; r.y2 = dev->size.y2; @@ -807,7 +807,7 @@ static void in_term(void *term_) struct links_event *ev; int r; unsigned char *iq; - if ((unsigned)term->qlen + ALLOC_GR > MAXINT) + if ((unsigned)term->qlen + ALLOC_GR > INT_MAX) overalloc(); iq = xrealloc(term->input_queue, term->qlen + ALLOC_GR); term->input_queue = iq; @@ -1014,7 +1014,7 @@ static void redraw_screen(struct terminal *term) { int x, y, p = 0; int cx = term->lcx, cy = term->lcy; - unsigned n_chars = MAXINT / 2; + unsigned n_chars = INT_MAX / 2; unsigned char *a; int attrib = -1; int mode = -1; diff --git a/types.c b/types.c @@ -1230,7 +1230,7 @@ struct assoc *get_type_assoc(struct terminal *term, unsigned char *type, int *n) if (a->system == SYSTEM_ID && (term->environment & ENV_XWIN ? a->xwin : a->cons) && is_in_list(a->ct, type, (int)strlen(cast_const_char type))) { - if (count == MAXINT) + if (count == INT_MAX) overalloc(); count++; } @@ -1238,7 +1238,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)) + if ((unsigned)count > INT_MAX / sizeof(struct assoc)) overalloc(); assoc_array = xmalloc(count * sizeof(struct assoc)); count = 0; diff --git a/view.c b/view.c @@ -115,7 +115,7 @@ void sort_links(struct f_data *f) int i; if (F) return; if (f->nlinks) qsort(f->links, f->nlinks, sizeof(struct link), (int (*)(const void *, const void *))comp_links); - if ((unsigned)f->y > MAXINT / sizeof(struct link *)) overalloc(); + if ((unsigned)f->y > INT_MAX / sizeof(struct link *)) overalloc(); f->lines1 = mem_calloc(f->y * sizeof(struct link *)); f->lines2 = mem_calloc(f->y * sizeof(struct link *)); for (i = 0; i < f->nlinks; i++) { @@ -191,7 +191,7 @@ static struct line_info *format_text_uncached(unsigned char *text, int width, in sk = 1; put: if (!(lnn & (ALLOC_GR-1))) { - if ((unsigned)lnn > MAXINT / sizeof(struct line_info) - ALLOC_GR) + if ((unsigned)lnn > INT_MAX / sizeof(struct line_info) - ALLOC_GR) overalloc(); ln = xrealloc(ln, (lnn + ALLOC_GR) * sizeof(struct line_info)); } @@ -269,7 +269,7 @@ struct line_info *format_text(unsigned char *text, int width, int wrap, int cp) ftce->cp == cp) goto have_it; } - if (text_len > MAXINT - sizeof(struct format_text_cache_entry)) overalloc(); + if (text_len > INT_MAX - sizeof(struct format_text_cache_entry)) overalloc(); ftce = xmalloc(sizeof(struct format_text_cache_entry) + text_len); memcpy(ftce->copied_text, text, text_len + 1); ftce->text_ptr = text; @@ -347,7 +347,7 @@ static void draw_link(struct terminal *t, struct f_data_c *scr, int l) struct form_state *fs = find_form_state(scr, link->form); q = area_cursor(scr, link->form, fs); } - if ((unsigned)link->n > MAXINT / sizeof(struct link_bg)) overalloc(); + if ((unsigned)link->n > INT_MAX / sizeof(struct link_bg)) overalloc(); scr->link_bg = xmalloc(link->n * sizeof(struct link_bg)); scr->link_bg_n = link->n; for (i = 0; i < link->n; i++) { @@ -444,7 +444,7 @@ static int is_in_range(struct f_data *f, int y, int yw, unsigned char *txt, int int found = 0; int l; int s1, s2; - *min = MAXINT; + *min = INT_MAX; *max = 0; if (!utf8) @@ -553,7 +553,7 @@ c: if (x >= xp && y >= yp && x < xp + xw && y < yp + yw) { if (!(len & (ALLOC_GR - 1))) { struct point *points2; - if ((unsigned)len > MAXINT / sizeof(struct point) - ALLOC_GR) + if ((unsigned)len > INT_MAX / sizeof(struct point) - ALLOC_GR) goto ret; points2 = xrealloc(points, sizeof(struct point) * (len + ALLOC_GR)); @@ -680,7 +680,7 @@ struct form_state *find_form_state(struct f_data_c *f, struct form_control *form if (n < vs->form_info_len) fs = &vs->form_info[n]; else { - if ((unsigned)n > MAXINT / sizeof(struct form_state) - 1) + if ((unsigned)n > INT_MAX / sizeof(struct form_state) - 1) overalloc(); fs = xrealloc(vs->form_info, (n + 1) * sizeof(struct form_state)); vs->form_info = fs; @@ -1231,14 +1231,14 @@ static void set_pos_x(struct f_data_c *f, struct link *l) { int i; int xm = 0; - int xl = MAXINT; + int xl = INT_MAX; for (i = 0; i < l->n; i++) { if (l->pos[i].y >= f->vs->view_pos && l->pos[i].y < f->vs->view_pos + f->yw) { if (l->pos[i].x >= xm) xm = l->pos[i].x + 1; if (l->pos[i].x < xl) xl = l->pos[i].x; } } - if (xl == MAXINT) return; + if (xl == INT_MAX) return; /*if ((f->vs->view_posx = xm - f->xw) > xl) f->vs->view_posx = xl;*/ if (f->vs->view_posx + f->xw < xm) f->vs->view_posx = xm - f->xw; if (f->vs->view_posx > xl) f->vs->view_posx = xl; @@ -1583,7 +1583,7 @@ static void encode_multipart(struct session *ses, struct list_head *l, unsigned bnd: add_to_str(data, len, cast_uchar "--"); if (!(nbound_ptrs & (ALLOC_GR-1))) { - if ((unsigned)nbound_ptrs > MAXINT / sizeof(int) - ALLOC_GR) + if ((unsigned)nbound_ptrs > INT_MAX / sizeof(int) - ALLOC_GR) overalloc(); bound_ptrs = xrealloc(bound_ptrs, (nbound_ptrs + ALLOC_GR) * sizeof(int)); @@ -1808,7 +1808,7 @@ static struct menu_item *clone_select_menu(struct menu_item *m) struct menu_item *n = NULL; int i = 0; do { - if ((unsigned)i > MAXINT / sizeof(struct menu_item) - 1) + if ((unsigned)i > INT_MAX / sizeof(struct menu_item) - 1) overalloc(); n = xrealloc(n, (i + 1) * sizeof(struct menu_item)); n[i].text = stracpy(m->text); diff --git a/view_gr.c b/view_gr.c @@ -555,7 +555,7 @@ static void g_get_search(struct f_data *f, unsigned char *s) if (!len) continue; if (!(f->n_search_positions & (ALLOC_GR - 1))) { - if ((unsigned)f->n_search_positions > MAXINT / sizeof(int) - ALLOC_GR) + if ((unsigned)f->n_search_positions > INT_MAX / sizeof(int) - ALLOC_GR) overalloc(); f->search_positions = xrealloc(f->search_positions, (f->n_search_positions + ALLOC_GR) * sizeof(int)); @@ -1495,7 +1495,7 @@ static struct g_object_text * g_find_nearest_object(struct f_data *f, int x, int fnd_obj = NULL; fnd_x = x; fnd_y = y; - fnd_obj_dist = MAXINT; + fnd_obj_dist = INT_MAX; if (f->root) find_nearest_sub(NULL, f->root); return fnd_obj; @@ -1526,8 +1526,8 @@ static void find_next_sub(struct g_object *p, struct g_object *c) get_object_pos(c, &x, &y); y += t->goti.go.yw / 2; yy = y; - if (yy < find_refline) yy += MAXINT / 2; - if (find_direction < 0) yy = MAXINT - yy; + if (yy < find_refline) yy += INT_MAX / 2; + if (find_direction < 0) yy = INT_MAX - yy; if (find_opt_yy == -1 || yy > find_opt_yy) { int sx, ex; unsigned char *tt; diff --git a/x.c b/x.c @@ -604,7 +604,7 @@ static void x_add_to_table(struct graphics_device* gd) if (!c) x_hash_table[a].pointer = xmalloc(sizeof(struct graphics_device *)); else { - if ((unsigned)c > MAXINT / sizeof(struct graphics_device *) - 1) + if ((unsigned)c > INT_MAX / sizeof(struct graphics_device *) - 1) overalloc(); x_hash_table[a].pointer = xrealloc(x_hash_table[a].pointer, (c + 1) * sizeof(struct graphics_device *)); @@ -2065,7 +2065,7 @@ static void addchr(unsigned char **str, size_t *l, unsigned char c) return; if ((*str)[*l]) *l = strlen((char *)*str); - if (*l > MAXINT - 2) + if (*l > INT_MAX - 2) overalloc(); s = xrealloc(*str, *l + 2); if (!s) {