diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2018-08-16 15:05:34 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2018-08-16 15:05:34 +0000 |
commit | dd0d3dcce42380000f428a36e07f1c43cbe8b506 (patch) | |
tree | 0bcca992a37e1a9838ee355738957b53e7bd9ba6 | |
parent | 0eda964d1aadc6a0e9d48b0b047de92144f8eec9 (diff) | |
download | mandoc-dd0d3dcce42380000f428a36e07f1c43cbe8b506.tar.gz |
Do not calculate a pointer to a memory location before the beginning of
a static array. Christos Zoulas, Robert Elz, and Andreas Gustafsson
point out that is undefined behaviour by the C standard even if we
never access the pointer.
-rw-r--r-- | man_validate.c | 5 | ||||
-rw-r--r-- | mdoc_validate.c | 5 |
2 files changed, 4 insertions, 6 deletions
diff --git a/man_validate.c b/man_validate.c index d6c51af5..8e2f6bee 100644 --- a/man_validate.c +++ b/man_validate.c @@ -54,7 +54,7 @@ static void post_UR(CHKARGS); static void post_in(CHKARGS); static void post_vs(CHKARGS); -static const v_check __man_valids[MAN_MAX - MAN_TH] = { +static const v_check man_valids[MAN_MAX - MAN_TH] = { post_TH, /* TH */ NULL, /* SH */ NULL, /* SS */ @@ -92,7 +92,6 @@ static const v_check __man_valids[MAN_MAX - MAN_TH] = { post_UR, /* MT */ NULL, /* ME */ }; -static const v_check *man_valids = __man_valids - MAN_TH; void @@ -138,7 +137,7 @@ man_node_validate(struct roff_man *man) break; } assert(n->tok >= MAN_TH && n->tok < MAN_MAX); - cp = man_valids + n->tok; + cp = man_valids + (n->tok - MAN_TH); if (*cp) (*cp)(man, n); if (man->last == n) diff --git a/mdoc_validate.c b/mdoc_validate.c index 75de366d..47eb1508 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -116,7 +116,7 @@ static void post_useless(POST_ARGS); static void post_xr(POST_ARGS); static void post_xx(POST_ARGS); -static const v_post __mdoc_valids[MDOC_MAX - MDOC_Dd] = { +static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = { post_dd, /* Dd */ post_dt, /* Dt */ post_os, /* Os */ @@ -238,7 +238,6 @@ static const v_post __mdoc_valids[MDOC_MAX - MDOC_Dd] = { NULL, /* %U */ NULL, /* Ta */ }; -static const v_post *const mdoc_valids = __mdoc_valids - MDOC_Dd; #define RSORD_MAX 14 /* Number of `Rs' blocks. */ @@ -357,7 +356,7 @@ mdoc_node_validate(struct roff_man *mdoc) } assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); - p = mdoc_valids + n->tok; + p = mdoc_valids + (n->tok - MDOC_Dd); if (*p) (*p)(mdoc); if (mdoc->last == n) |