diff options
author | 2015-01-30 04:08:37 +0000 | |
---|---|---|
committer | 2015-01-30 04:08:37 +0000 | |
commit | 5f6d1ba3b66a0636257aba86b42ff1aeebe41e24 (patch) | |
tree | 21eb744794322a2704c769b60d64b4a4c721ba1d | |
parent | Auditing the tbl(7) code for more NULL pointer accesses, i came out (diff) | |
download | wireguard-openbsd-5f6d1ba3b66a0636257aba86b42ff1aeebe41e24.tar.xz wireguard-openbsd-5f6d1ba3b66a0636257aba86b42ff1aeebe41e24.zip |
Abolish struct tbl_head and replace it by an "int col" member in
struct tbl_cell. No functional change, minus 40 lines of code.
Diffstat (limited to '')
-rw-r--r-- | usr.bin/mandoc/libroff.h | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 16 | ||||
-rw-r--r-- | usr.bin/mandoc/out.c | 4 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl.c | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_data.c | 11 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_html.c | 16 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_layout.c | 33 | ||||
-rw-r--r-- | usr.bin/mandoc/tbl_term.c | 37 |
8 files changed, 40 insertions, 89 deletions
diff --git a/usr.bin/mandoc/libroff.h b/usr.bin/mandoc/libroff.h index 4041dafba54..942d1f630fe 100644 --- a/usr.bin/mandoc/libroff.h +++ b/usr.bin/mandoc/libroff.h @@ -1,4 +1,4 @@ -/* $OpenBSD: libroff.h,v 1.15 2015/01/28 17:30:37 schwarze Exp $ */ +/* $OpenBSD: libroff.h,v 1.16 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -34,8 +34,6 @@ struct tbl_node { struct tbl_span *first_span; struct tbl_span *current_span; struct tbl_span *last_span; - struct tbl_head *first_head; - struct tbl_head *last_head; struct tbl_node *next; }; diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index a56e7578f7d..a47a8e08df1 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.134 2015/01/28 21:10:28 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.135 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2015 Ingo Schwarze <schwarze@openbsd.org> @@ -204,17 +204,6 @@ struct tbl_opts { int rvert; /* width of right vertical line */ }; -/* - * The head of a table specifies all of its columns. When formatting a - * tbl_span, iterate over these and plug in data from the tbl_span when - * appropriate, using tbl_cell as a guide to placement. - */ -struct tbl_head { - int ident; /* 0 <= unique id < cols */ - struct tbl_head *next; - struct tbl_head *prev; -}; - enum tbl_cellt { TBL_CELL_CENTRE, /* c, C */ TBL_CELL_RIGHT, /* r, R */ @@ -236,6 +225,7 @@ struct tbl_cell { int vert; /* width of subsequent vertical line */ enum tbl_cellt pos; size_t spacing; + int col; /* column number, starting from 0 */ int flags; #define TBL_CELL_TALIGN (1 << 0) /* t, T */ #define TBL_CELL_BALIGN (1 << 1) /* d, D */ @@ -245,7 +235,6 @@ struct tbl_cell { #define TBL_CELL_UP (1 << 5) /* u, U */ #define TBL_CELL_WIGN (1 << 6) /* z, Z */ #define TBL_CELL_WMAX (1 << 7) /* x, X */ - struct tbl_head *head; }; /* @@ -290,7 +279,6 @@ enum tbl_spant { */ struct tbl_span { struct tbl_opts *opts; - struct tbl_head *head; struct tbl_row *layout; /* layout row */ struct tbl_dat *first; struct tbl_dat *last; diff --git a/usr.bin/mandoc/out.c b/usr.bin/mandoc/out.c index d939e88856b..7d3f8fd09ac 100644 --- a/usr.bin/mandoc/out.c +++ b/usr.bin/mandoc/out.c @@ -1,4 +1,4 @@ -/* $OpenBSD: out.c,v 1.30 2015/01/28 02:23:33 schwarze Exp $ */ +/* $OpenBSD: out.c,v 1.31 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -138,7 +138,7 @@ tblcalc(struct rofftbl *tbl, const struct tbl_span *sp, spans = dp->spans; if (1 < spans) continue; - icol = dp->layout->head->ident; + icol = dp->layout->col; if (maxcol < icol) maxcol = icol; col = tbl->cols + icol; diff --git a/usr.bin/mandoc/tbl.c b/usr.bin/mandoc/tbl.c index e5af6b3efa4..9af8a34a6a1 100644 --- a/usr.bin/mandoc/tbl.c +++ b/usr.bin/mandoc/tbl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl.c,v 1.18 2015/01/30 02:08:37 schwarze Exp $ */ +/* $OpenBSD: tbl.c,v 1.19 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -106,7 +106,6 @@ tbl_free(struct tbl_node *tbl) struct tbl_cell *cp; struct tbl_span *sp; struct tbl_dat *dp; - struct tbl_head *hp; while ((rp = tbl->first_row) != NULL) { tbl->first_row = rp->next; @@ -129,11 +128,6 @@ tbl_free(struct tbl_node *tbl) free(sp); } - while ((hp = tbl->first_head) != NULL) { - tbl->first_head = hp->next; - free(hp); - } - free(tbl); } diff --git a/usr.bin/mandoc/tbl_data.c b/usr.bin/mandoc/tbl_data.c index 710f3105011..75ea87db76b 100644 --- a/usr.bin/mandoc/tbl_data.c +++ b/usr.bin/mandoc/tbl_data.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_data.c,v 1.24 2015/01/30 02:08:37 schwarze Exp $ */ +/* $OpenBSD: tbl_data.c,v 1.25 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -42,13 +42,9 @@ getdata(struct tbl_node *tbl, struct tbl_span *dp, struct tbl_cell *cp; int sv; - cp = dp->last == NULL ? dp->layout->first : dp->last->layout->next; - - /* - * Skip over spanners, since - * we want to match data with data layout cells in the header. - */ + /* Advance to the next layout cell, skipping spanners. */ + cp = dp->last == NULL ? dp->layout->first : dp->last->layout->next; while (cp != NULL && cp->pos == TBL_CELL_SPAN) cp = cp->next; @@ -170,7 +166,6 @@ newspan(struct tbl_node *tbl, int line, struct tbl_row *rp) dp->line = line; dp->opts = &tbl->opts; dp->layout = rp; - dp->head = tbl->first_head; dp->prev = tbl->last_span; if (dp->prev == NULL) { diff --git a/usr.bin/mandoc/tbl_html.c b/usr.bin/mandoc/tbl_html.c index 272352683de..830a663492e 100644 --- a/usr.bin/mandoc/tbl_html.c +++ b/usr.bin/mandoc/tbl_html.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_html.c,v 1.9 2015/01/30 02:08:37 schwarze Exp $ */ +/* $OpenBSD: tbl_html.c,v 1.10 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -47,10 +47,10 @@ html_tbl_strlen(const char *p, void *arg) static void html_tblopen(struct html *h, const struct tbl_span *sp) { - const struct tbl_head *hp; struct htmlpair tag; struct roffsu su; struct roffcol *col; + int ic; if (sp->flags & TBL_SPAN_FIRST) { h->tbl.len = html_tbl_len; @@ -62,9 +62,9 @@ html_tblopen(struct html *h, const struct tbl_span *sp) PAIR_CLASS_INIT(&tag, "tbl"); h->tblt = print_otag(h, TAG_TABLE, 1, &tag); - for (hp = sp->head; hp; hp = hp->next) { + for (ic = 0; ic < sp->opts->cols; ic++) { bufinit(h); - col = &h->tbl.cols[hp->ident]; + col = h->tbl.cols + ic; SCALE_HS_INIT(&su, col->width); bufcat_su(h, "width", &su); PAIR_STYLE_INIT(&tag, h); @@ -86,10 +86,10 @@ print_tblclose(struct html *h) void print_tbl(struct html *h, const struct tbl_span *sp) { - const struct tbl_head *hp; const struct tbl_dat *dp; struct htmlpair tag; struct tag *tt; + int ic; /* Inhibit printing of spaces: we do padding ourselves. */ @@ -112,12 +112,12 @@ print_tbl(struct html *h, const struct tbl_span *sp) break; default: dp = sp->first; - for (hp = sp->head; hp; hp = hp->next) { + for (ic = 0; ic < sp->opts->cols; ic++) { print_stagq(h, tt); print_otag(h, TAG_TD, 0, NULL); - if (dp == NULL) - break; + if (dp == NULL || dp->layout->col > ic) + continue; if (dp->layout->pos != TBL_CELL_DOWN) if (dp->string != NULL) print_text(h, dp->string); diff --git a/usr.bin/mandoc/tbl_layout.c b/usr.bin/mandoc/tbl_layout.c index 5d4057a341e..f50d3aeb365 100644 --- a/usr.bin/mandoc/tbl_layout.c +++ b/usr.bin/mandoc/tbl_layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_layout.c,v 1.23 2015/01/30 02:08:37 schwarze Exp $ */ +/* $OpenBSD: tbl_layout.c,v 1.24 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -280,7 +280,7 @@ tbl_layout(struct tbl_node *tbl, int ln, const char *p, int pos) if (tbl->opts.lvert < rp->vert) tbl->opts.lvert = rp->vert; if (rp->last != NULL && - rp->last->head == tbl->last_head && + rp->last->col + 1 == tbl->opts.cols && tbl->opts.rvert < rp->last->vert) tbl->opts.rvert = rp->last->vert; @@ -322,38 +322,19 @@ static struct tbl_cell * cell_alloc(struct tbl_node *tbl, struct tbl_row *rp, enum tbl_cellt pos) { struct tbl_cell *p, *pp; - struct tbl_head *h, *hp; p = mandoc_calloc(1, sizeof(*p)); + p->pos = pos; if ((pp = rp->last) != NULL) { pp->next = p; - h = pp->head->next; - } else { + p->col = pp->col + 1; + } else rp->first = p; - h = tbl->first_head; - } rp->last = p; - p->pos = pos; - - /* Re-use header. */ - - if (h != NULL) { - p->head = h; - return(p); - } - - hp = mandoc_calloc(1, sizeof(*hp)); - hp->ident = tbl->opts.cols++; - - if (tbl->last_head != NULL) { - hp->prev = tbl->last_head; - tbl->last_head->next = hp; - } else - tbl->first_head = hp; - tbl->last_head = hp; + if (tbl->opts.cols <= p->col) + tbl->opts.cols = p->col + 1; - p->head = hp; return(p); } diff --git a/usr.bin/mandoc/tbl_term.c b/usr.bin/mandoc/tbl_term.c index 07ace637ec6..91cda335046 100644 --- a/usr.bin/mandoc/tbl_term.c +++ b/usr.bin/mandoc/tbl_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tbl_term.c,v 1.23 2015/01/30 02:08:37 schwarze Exp $ */ +/* $OpenBSD: tbl_term.c,v 1.24 2015/01/30 04:08:37 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org> @@ -58,12 +58,11 @@ term_tbl_len(size_t sz, void *arg) void term_tbl(struct termp *tp, const struct tbl_span *sp) { - const struct tbl_head *hp; const struct tbl_cell *cp; const struct tbl_dat *dp; static size_t offset; size_t rmargin, maxrmargin, tsz; - int horiz, spans, vert; + int ic, horiz, spans, vert; rmargin = tp->rmargin; maxrmargin = tp->maxrmargin; @@ -95,8 +94,8 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) if (sp->opts->opts & TBL_OPT_CENTRE) { tsz = sp->opts->opts & (TBL_OPT_BOX | TBL_OPT_DBOX) ? 2 : !!sp->opts->lvert + !!sp->opts->rvert; - for (hp = sp->head; hp != NULL; hp = hp->next) - tsz += tp->tbl.cols[hp->ident].width + 3; + for (ic = 0; ic < sp->opts->cols; ic++) + tsz += tp->tbl.cols[ic].width + 3; tsz -= 3; if (offset + tsz > rmargin) tsz -= 1; @@ -125,16 +124,14 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) /* * Now print the actual data itself depending on the span type. - * Spanner spans get a horizontal rule; data spanners have their - * data printed by matching data to header. + * Match data cells to column numbers. */ if (sp->pos == TBL_SPAN_DATA) { - /* Iterate over template headers. */ cp = sp->layout->first; dp = sp->first; spans = 0; - for (hp = sp->head; hp != NULL; hp = hp->next) { + for (ic = 0; ic < sp->opts->cols; ic++) { /* * Remeber whether we need a vertical bar @@ -148,8 +145,7 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) */ if (spans == 0) { - tbl_data(tp, sp->opts, dp, - tp->tbl.cols + hp->ident); + tbl_data(tp, sp->opts, dp, tp->tbl.cols + ic); if (dp != NULL) { spans = dp->spans; dp = dp->next; @@ -164,13 +160,13 @@ term_tbl(struct termp *tp, const struct tbl_span *sp) * of spans and after the last cell. */ - if (hp->next == NULL || spans) + if (ic + 1 == sp->opts->cols || spans) continue; tbl_char(tp, ASCII_NBRSP, 1); if (vert > 0) tbl_char(tp, '|', vert); - if (vert < 2 && hp->next != NULL) + if (vert < 2) tbl_char(tp, ASCII_NBRSP, 2 - vert); } } else if (horiz) @@ -234,7 +230,7 @@ tbl_hrule(struct termp *tp, const struct tbl_span *sp, int kind) if (c2 == c1) c2 = NULL; for (;;) { - tbl_char(tp, line, tp->tbl.cols[c1->head->ident].width + 1); + tbl_char(tp, line, tp->tbl.cols[c1->col].width + 1); vert = c1->vert; if ((c1 = c1->next) == NULL) break; @@ -330,17 +326,16 @@ static void tbl_literal(struct termp *tp, const struct tbl_dat *dp, const struct roffcol *col) { - struct tbl_head *hp; - size_t width, len, padl, padr; - int spans; + size_t len, padl, padr, width; + int ic, spans; assert(dp->string); len = term_strlen(tp, dp->string); - - hp = dp->layout->head->next; width = col->width; - for (spans = dp->spans; spans--; hp = hp->next) - width += tp->tbl.cols[hp->ident].width + 3; + ic = dp->layout->col; + spans = dp->spans; + while (spans--) + width += tp->tbl.cols[++ic].width + 3; padr = width > len ? width - len : 0; padl = 0; |