Commit: c803d3c7a47816cdcac20fc4e90a0e2a0cd815f8
Parent: 156e54ea6e3f7ac56e7aacf0df93e983b129e0e3
Author: opask
Date: Fri, 20 Jul 2018 20:13:11 -0600
remove most DUMMY values, update TODO
Diffstat:
17 files changed, 64 insertions(+), 58 deletions(-)
diff --git a/TODO b/TODO
@@ -41,3 +41,6 @@
- fix command-line flag handling
- remove if (x) free(x), it only guards against free(NULL) which is a no-op
+
+- remove DUMMY from http[,s].c and connect.c, changing to NULL breaks https
+ sites
diff --git a/bfu.c b/bfu.c
@@ -1194,7 +1194,7 @@ static void do_tab_compl(struct terminal *term, struct list_head *history, struc
int l = (int)strlen(cast_const_char cdata), n = 0;
struct history_item *hi;
struct list_head *lhi;
- struct menu_item *items = DUMMY;
+ struct menu_item *items = NULL;
foreach(struct history_item, hi, lhi, *history) {
unsigned char *s = dlg_get_history_string(term, hi, MAXINT);
if (!strncmp(cast_const_char cdata, cast_const_char s, l)) {
@@ -2222,7 +2222,7 @@ void msg_box(struct terminal *term, struct memory_list *ml, unsigned char *title
int udatan;
va_list ap;
va_start(ap, align);
- udata = DUMMY;
+ udata = NULL;
udatan = 0;
do {
text = va_arg(ap, unsigned char *);
diff --git a/dither.c b/dither.c
@@ -45,7 +45,7 @@
*/
/* We assume here int holds at least 32 bits */
-static int *red_table = DUMMY, *green_table = DUMMY, *blue_table = DUMMY;
+static int *red_table = NULL, *green_table = NULL, *blue_table = NULL;
static int table_16 = 1;
/* If we want to represent some 16-bit from-screen-light, it would require certain display input
@@ -992,9 +992,12 @@ void round_color_sRGB_to_48(unsigned short *restrict red, unsigned short *restri
void free_dither(void)
{
- if (red_table) mem_free(red_table), red_table = DUMMY;
- if (green_table) mem_free(green_table), green_table = DUMMY;
- if (blue_table) mem_free(blue_table), blue_table = DUMMY;
+ free(red_table);
+ red_table = NULL;
+ free(green_table);
+ green_table = NULL;
+ free(blue_table);
+ blue_table = NULL;
}
#endif
diff --git a/error.c b/error.c
@@ -111,7 +111,8 @@ void *mem_calloc_(size_t size, int mayfail)
{
void *p;
debug_test_free(NULL, 0);
- if (!size) return DUMMY;
+ if (!size)
+ return NULL;
retry:
if (!(p = heap_calloc(size))) {
if (out_of_memory_fl(0, !mayfail ? cast_uchar "calloc" : NULL, size, NULL, 0)) goto retry;
@@ -122,26 +123,20 @@ void *mem_calloc_(size_t size, int mayfail)
void mem_free(void *p)
{
- if (p == DUMMY) return;
- if (!p) {
- internal("mem_free(NULL)");
+ if (!p)
return;
- }
heap_free(p);
}
void *mem_realloc_(void *p, size_t size, int mayfail)
{
void *np;
- if (p == DUMMY) return xmalloc(size);
+ if (!p)
+ return xmalloc(size);
debug_test_free(NULL, 0);
- if (!p) {
- internal("mem_realloc(NULL, %lu)", (unsigned long)size);
- return NULL;
- }
if (!size) {
mem_free(p);
- return DUMMY;
+ return NULL;
}
retry:
if (!(np = heap_realloc(p, size))) {
diff --git a/file.c b/file.c
@@ -278,7 +278,8 @@ void file_func(struct connection *c)
setcstate(c, get_error_from_errno(er)); abort_connection(c); return;
}
dir:
- dir = DUMMY, dirl = 0;
+ dir = NULL;
+ dirl = 0;
if (name[0] && !dir_sep(name[strlen(cast_const_char name) - 1])) {
if (!c->cache) {
if (get_connection_cache_entry(c)) {
diff --git a/html.c b/html.c
@@ -120,7 +120,7 @@ int get_attr_val_nl = 0;
unsigned char *get_attr_val(unsigned char *e, unsigned char *name)
{
unsigned char *n;
- unsigned char *a = DUMMY;
+ unsigned char *a = NULL;
int l = 0;
int f;
aa:
@@ -2026,7 +2026,7 @@ static void new_menu_item(unsigned char *name, long data, int fullname)
static void init_menu(void)
{
menu_stack_size = 0;
- menu_stack = DUMMY;
+ menu_stack = NULL;
new_menu_item(stracpy(cast_uchar ""), -1, 0);
}
@@ -2052,7 +2052,8 @@ static struct menu_item *detach_menu(void)
static void destroy_menu(void)
{
- if (menu_stack && menu_stack != DUMMY) free_menu(menu_stack[0]);
+ if (menu_stack)
+ free_menu(menu_stack[0]);
detach_menu();
}
@@ -2115,7 +2116,7 @@ static int do_html_select(unsigned char *attr, unsigned char *html, unsigned cha
lbl_l = 0;
vlbl = NULL;
vlbl_l = 0;
- val = DUMMY;
+ val = NULL;
order = 0, group = 0, preselect = -1;
init_menu();
se:
@@ -2405,7 +2406,7 @@ static void parse_frame_widths(unsigned char *a, int ww, int www, int **op, int
int *oo, *o;
int ol;
ol = 0;
- o = DUMMY;
+ o = NULL;
new_ch:
while (WHITECHAR(*a)) a++;
n = strtoul(cast_const_char a, (char **)(void *)&a, 10);
diff --git a/html_gr.c b/html_gr.c
@@ -552,7 +552,7 @@ static void do_image(struct g_part *p, struct image_description *im)
map = mem_realloc(map, sizeof(struct image_map) + (map->n_areas + 1) * sizeof(struct map_area));
a = &map->area[map->n_areas++];
a->shape = shape;
- a->coords = DUMMY;
+ a->coords = NULL;
a->ncoords = 0;
if (ld->coords) {
unsigned char *p = ld->coords;
@@ -584,7 +584,7 @@ static void do_image(struct g_part *p, struct image_description *im)
if (!(link = new_link(p->data)))
a->link_num = -1;
else {
- link->pos = DUMMY;
+ link->pos = NULL;
link->type = L_LINK;
link->where = stracpy(ld->link);
link->target = stracpy(ld->target);
@@ -905,7 +905,7 @@ static void g_put_chars(void *p_, unsigned char *s, int l)
if (!(link = new_link(p->data)))
goto back_link;
link->num = p->link_num - 1;
- link->pos = DUMMY;
+ link->pos = NULL;
if (!last_form) {
link->type = L_LINK;
link->where = stracpy(last_link);
diff --git a/html_r.c b/html_r.c
@@ -10,17 +10,17 @@ struct f_data *init_formatted(struct document_options *opt)
struct f_data *scr;
scr = mem_calloc(sizeof(struct f_data));
copy_opt(&scr->opt, opt);
- scr->data = DUMMY;
+ scr->data = NULL;
scr->nlinks = 0;
- scr->links = DUMMY;
+ scr->links = NULL;
init_list(scr->forms);
init_list(scr->tags);
init_list(scr->nodes);
#ifdef G
scr->n_images=0;
init_list(scr->images);
- scr->search_positions = DUMMY;
- scr->search_lengths = DUMMY;
+ scr->search_positions = NULL;
+ scr->search_lengths = NULL;
init_list(scr->image_refresh);
scr->start_highlight_x = -1;
scr->start_highlight_y = -1;
@@ -255,7 +255,7 @@ static void xpand_lines(struct part *p, int y)
for (i = p->data->y; i < y; i++) {
p->data->data[i].l = 0;
p->data->data[i].allocated = 0;
- p->data->data[i].d = DUMMY;
+ p->data->data[i].d = NULL;
}
p->data->y = y;
}
@@ -580,7 +580,7 @@ static void put_chars(void *p_, unsigned char *c, int l)
static struct text_attrib_beginning ta_cache = { -1, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, 0, 0 };
static int bg_cache;
static int fg_cache;
- char_t *uni_c = DUMMY;
+ char_t *uni_c = NULL;
int bg, fg;
int i;
@@ -749,7 +749,7 @@ static void put_chars(void *p_, unsigned char *c, int l)
if (!p->data) goto no_l;
if (!(link = new_link(p->data))) goto no_l;
link->num = p->link_num - 1;
- link->pos = DUMMY;
+ link->pos = NULL;
if (!last_form) {
link->type = L_LINK;
link->where = stracpy(last_link);
@@ -1029,7 +1029,7 @@ struct part *format_html_part(unsigned char *start, unsigned char *end, int alig
p->xp = xs; p->yp = ys;
/*p->xmax = p->xa = 0;*/
p->attribute = get_attribute(find_nearest_color(&format_.fg, 16), find_nearest_color(&par_format.bgcolor, 8));
- p->spaces = DUMMY;
+ p->spaces = NULL;
/*p->z_spaces = 0;*/
/*p->spl = 0;*/
p->link_num = link_num;
diff --git a/html_tbl.c b/html_tbl.c
@@ -193,12 +193,12 @@ static struct table *new_table(void)
t->p = NULL;
#ifdef G
t->gp = NULL;
- t->r_frame = DUMMY;
+ t->r_frame = NULL;
t->nr_frame = 0;
- t->r_bg = DUMMY;
+ t->r_bg = NULL;
t->nr_bg = 0;
- t->r_cells = DUMMY;
- t->w_cells = DUMMY;
+ t->r_cells = NULL;
+ t->w_cells = NULL;
t->nr_cells = 0;
#endif
t->x = t->y = 0;
@@ -208,9 +208,9 @@ static struct table *new_table(void)
t->c = 0;
t->rc = INIT_X;
t->cols = mem_calloc(INIT_X * sizeof(struct table_column));
- t->xcols = DUMMY;
+ t->xcols = NULL;
t->xc = 0;
- t->r_heights = DUMMY;
+ t->r_heights = NULL;
return t;
}
@@ -417,7 +417,7 @@ static struct table *parse_table(unsigned char *html, unsigned char *eof, unsign
memcpy(&l_col, bgcolor, sizeof(struct rgb));
*end = html;
if (bad_html) {
- *bad_html = DUMMY;
+ *bad_html = NULL;
*bhp = 0;
}
t = new_table();
@@ -1609,7 +1609,10 @@ static void add_to_cell_sets(struct table_cell ****s, int **nn, int *n, struct r
if ((unsigned)i > MAXINT / sizeof(int *) - 1) overalloc();
ns = mem_realloc(*s, (i + 1) * sizeof(struct table_cell **));
nnn = mem_realloc(*nn, (i + 1) * sizeof(int));
- for (j = *n; j < i + 1; j++) ns[j] = DUMMY, nnn[j] = 0;
+ for (j = *n; j < i + 1; j++) {
+ ns[j] = NULL;
+ nnn[j] = 0;
+ }
*s = ns;
*nn = nnn;
*n = i + 1;
diff --git a/kbd.c b/kbd.c
@@ -315,7 +315,7 @@ void handle_trm(int std_in, int std_out, int sock_in, int sock_out, int ctl_in,
itrm->blocked = 0;
itrm->qlen = 0;
itrm->tm = NULL;
- itrm->ev_queue = DUMMY;
+ itrm->ev_queue = NULL;
itrm->eqlen = 0;
setraw(itrm->ctl_in, 1);
set_handlers(std_in, in_kbd, NULL, itrm);
diff --git a/os_dep.c b/os_dep.c
@@ -823,7 +823,7 @@ static const struct {
struct open_in_new *get_open_in_new(int environment)
{
int i;
- struct open_in_new *oin = DUMMY;
+ struct open_in_new *oin = NULL;
int noin = 0;
if (anonymous) return NULL;
if (environment & ENV_G) environment = ENV_G;
@@ -838,7 +838,6 @@ struct open_in_new *get_open_in_new(int environment)
oin[noin].hk = NULL;
oin[noin].open_window_fn = NULL;
}
- if (oin == DUMMY) return NULL;
return oin;
}
@@ -861,7 +860,7 @@ void set_highpri(void)
void os_seed_random(unsigned char **pool, int *pool_size)
{
- *pool = DUMMY;
+ *pool = NULL;
*pool_size = 0;
}
diff --git a/select.c b/select.c
@@ -32,7 +32,7 @@ struct thread {
#endif
};
-static struct thread *threads = DUMMY;
+static struct thread *threads = NULL;
static int n_threads = 0;
static fd_set w_read;
diff --git a/session.c b/session.c
@@ -425,7 +425,6 @@ static void abort_download(void *down_)
static void abort_and_delete_download(void *down_)
{
struct download *down = (struct download *)down_;
- if (!down->prog) down->prog = DUMMY;
abort_download(down);
}
diff --git a/terminal.c b/terminal.c
@@ -594,10 +594,10 @@ struct terminal *init_term(int fdin, int fdout, void (*root_window)(struct windo
term->lcy = -1;
term->dirty = 1;
term->blocked = -1;
- term->screen = DUMMY;
- term->last_screen = DUMMY;
+ term->screen = NULL;
+ term->last_screen = NULL;
term->spec = default_term_spec(cast_uchar "");
- term->input_queue = DUMMY;
+ term->input_queue = NULL;
init_list(term->windows);
term->handle_to_close = -1;
win = mem_calloc(sizeof(struct window));
diff --git a/url.c b/url.c
@@ -1087,7 +1087,7 @@ static unsigned char *display_url_or_host(struct terminal *term, unsigned char *
add_to_strn(&ret, url_conv);
} else {
ret = url_conv;
- url_conv = DUMMY;
+ url_conv = NULL;
}
} else {
ret = convert(utf8_table, term_charset(term), url, NULL);
diff --git a/view.c b/view.c
@@ -28,7 +28,7 @@ struct view_state *create_vs(void)
vs->orig_link = -1;
vs->frame_pos = -1;
vs->plain = -1;
- vs->form_info = DUMMY;
+ vs->form_info = NULL;
vs->form_info_len = 0;
return vs;
}
@@ -190,7 +190,7 @@ int textptr_diff(unsigned char *t2, unsigned char *t1, int cp)
static struct line_info *format_text_uncached(unsigned char *text, int width, int wrap, int cp)
{
- struct line_info *ln = DUMMY;
+ struct line_info *ln = NULL;
int lnn = 0;
unsigned char *b = text;
int sk, ps = 0;
@@ -507,7 +507,7 @@ static int get_searched(struct f_data_c *scr, struct point **pt, int *pl)
int s1, s2;
int l;
unsigned c;
- struct point *points = DUMMY;
+ struct point *points = NULL;
int len = 0;
unsigned char *ww;
unsigned char *w = scr->ses->search_word;
@@ -1863,7 +1863,7 @@ static void encode_multipart(struct session *ses, struct list_head *l, unsigned
unsigned char *bound, int cp_from, int cp_to)
{
int errn;
- int *bound_ptrs = DUMMY;
+ int *bound_ptrs = NULL;
int nbound_ptrs = 0;
unsigned char *m1, *m2;
struct submitted_value *sv = NULL; /* against warning */
@@ -2094,7 +2094,7 @@ static unsigned char *get_link_url(struct session *ses, struct f_data_c *f, stru
static struct menu_item *clone_select_menu(struct menu_item *m)
{
- struct menu_item *n = DUMMY;
+ struct menu_item *n = NULL;
int i = 0;
do {
if ((unsigned)i > MAXINT / sizeof(struct menu_item) - 1) overalloc();
diff --git a/view_gr.c b/view_gr.c
@@ -514,7 +514,9 @@ static void g_get_search(struct f_data *f, unsigned char *s)
if (f->last_search && !strcmp(cast_const_char f->last_search, cast_const_char s)) return;
mem_free(f->search_positions);
mem_free(f->search_lengths);
- f->search_positions = DUMMY, f->search_lengths = DUMMY, f->n_search_positions = 0;
+ f->search_positions = NULL;
+ f->search_lengths = NULL;
+ f->n_search_positions = 0;
if (f->last_search) mem_free(f->last_search);
if (!(f->last_search = stracpy(s))) return;
for (i = 0; i < f->srch_string_size; i++) {