diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-01-10 15:31:00 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-01-10 15:31:00 +0000 |
commit | ed5e3c51cf000a55a9774ad85994aa7c35abc0df (patch) | |
tree | 3038b4cd4495d286fb7980c27cff8a70b29e27f5 | |
parent | 8a26b665a342bbb1c095e7556e69d0995f952fe8 (diff) | |
download | mandoc-ed5e3c51cf000a55a9774ad85994aa7c35abc0df.tar.gz |
Clarify what members may be NULL or not in calculating widths. Make
sure signedness is correct. Verify that layouts MUST exit for data
cells.
-rw-r--r-- | mandoc.h | 20 | ||||
-rw-r--r-- | out.c | 23 | ||||
-rw-r--r-- | tbl_data.c | 5 | ||||
-rw-r--r-- | tbl_layout.c | 2 |
4 files changed, 27 insertions, 23 deletions
@@ -200,7 +200,7 @@ enum tbl_cellt { struct tbl_cell { struct tbl_cell *next; enum tbl_cellt pos; - int spacing; + size_t spacing; int flags; #define TBL_CELL_TALIGN (1 << 0) /* t, T */ #define TBL_CELL_BALIGN (1 << 1) /* d, D */ @@ -222,12 +222,12 @@ struct tbl_row { }; enum tbl_datt { - TBL_DATA_NONE, - TBL_DATA_DATA, - TBL_DATA_HORIZ, - TBL_DATA_DHORIZ, - TBL_DATA_NHORIZ, - TBL_DATA_NDHORIZ + TBL_DATA_NONE, /* has no data */ + TBL_DATA_DATA, /* consists of data/string */ + TBL_DATA_HORIZ, /* horizontal line */ + TBL_DATA_DHORIZ, /* double-horizontal line */ + TBL_DATA_NHORIZ, /* squeezed horizontal line */ + TBL_DATA_NDHORIZ /* squeezed double-horizontal line */ }; /* @@ -235,10 +235,10 @@ enum tbl_datt { * string value that's in the cell. The rest is layout. */ struct tbl_dat { - struct tbl_cell *layout; /* layout cell: CAN BE NULL */ + struct tbl_cell *layout; /* layout cell */ int spans; /* how many spans follow */ struct tbl_dat *next; - char *string; + char *string; /* data (NULL if not TBL_DATA_DATA) */ enum tbl_datt pos; }; @@ -254,7 +254,7 @@ enum tbl_spant { struct tbl_span { struct tbl *tbl; struct tbl_head *head; - struct tbl_row *layout; /* layout row: CAN BE NULL */ + struct tbl_row *layout; /* layout row */ struct tbl_dat *first; struct tbl_dat *last; int flags; @@ -464,6 +464,7 @@ tblcalc_literal(struct rofftbl *tbl, struct roffcol *col, const struct tbl_dat *dp) { size_t sz, bufsz, spsz; + const char *str; /* * Calculate our width and use the spacing, with a minimum @@ -471,9 +472,11 @@ tblcalc_literal(struct rofftbl *tbl, struct roffcol *col, * either side, while right/left get a single adjacent space). */ - sz = bufsz = spsz = 0; - if (dp->string) - sz = (*tbl->slen)(dp->string, tbl->arg); + bufsz = spsz = 0; + str = dp->string ? dp->string : ""; + sz = (*tbl->slen)(str, tbl->arg); + + /* FIXME: TBL_DATA_HORIZ et al.? */ assert(dp->layout); switch (dp->layout->pos) { @@ -502,9 +505,9 @@ tblcalc_number(struct rofftbl *tbl, struct roffcol *col, const struct tbl *tp, const struct tbl_dat *dp) { int i; - size_t sz, psz, ssz, d, max; - char *cp; + size_t sz, psz, ssz, d; const char *str; + char *cp; char buf[2]; /* @@ -516,11 +519,11 @@ tblcalc_number(struct rofftbl *tbl, struct roffcol *col, * Finally, re-assign the stored values. */ - str = dp && dp->string ? dp->string : ""; - max = dp && dp->layout ? dp->layout->spacing : 0; - + str = dp->string ? dp->string : ""; sz = (*tbl->slen)(str, tbl->arg); + /* FIXME: TBL_DATA_HORIZ et al.? */ + buf[0] = tp->decimal; buf[1] = '\0'; @@ -556,8 +559,8 @@ tblcalc_number(struct rofftbl *tbl, struct roffcol *col, /* Adjust for stipulated width. */ - if (col->width < max) - col->width = max; + if (col->width < dp->layout->spacing) + col->width = dp->layout->spacing; } @@ -188,8 +188,6 @@ tbl_data(struct tbl_node *tbl, int ln, const char *p) * If there's no last parsed span, use the first row. Lastly, * if the last span was a horizontal line, use the same layout * (it doesn't "consume" the layout). - * - * In the end, this can be NULL! */ if (tbl->last_span) { @@ -198,11 +196,14 @@ tbl_data(struct tbl_node *tbl, int ln, const char *p) rp = tbl->last_span->layout->next; else rp = tbl->last_span->layout; + if (NULL == rp) rp = tbl->last_span->layout; } else rp = tbl->first_row; + assert(rp); + dp = mandoc_calloc(1, sizeof(struct tbl_span)); dp->tbl = &tbl->opts; dp->layout = rp; diff --git a/tbl_layout.c b/tbl_layout.c index ea93f645..25b77e1c 100644 --- a/tbl_layout.c +++ b/tbl_layout.c @@ -122,7 +122,7 @@ mod: } *pos += i; - cp->spacing = atoi(buf); + cp->spacing = (size_t)atoi(buf); goto mod; /* NOTREACHED */ |