From b3f54129b83e153bde2b769c0f1d2e2e774cc153 Mon Sep 17 00:00:00 2001 From: schwarze Date: Thu, 16 Aug 2018 15:04:45 +0000 Subject: [PATCH] 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. --- usr.bin/mandoc/man_validate.c | 7 +++---- usr.bin/mandoc/mdoc_validate.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/usr.bin/mandoc/man_validate.c b/usr.bin/mandoc/man_validate.c index 4c303d8bbf9..d35048d030b 100644 --- a/usr.bin/mandoc/man_validate.c +++ b/usr.bin/mandoc/man_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man_validate.c,v 1.105 2018/04/11 17:10:35 schwarze Exp $ */ +/* $OpenBSD: man_validate.c,v 1.106 2018/08/16 15:04:45 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2018 Ingo Schwarze @@ -52,7 +52,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 */ @@ -90,7 +90,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 @@ -136,7 +135,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/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index cbc6282d2eb..03a5c038db1 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.275 2018/08/01 16:00:54 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.276 2018/08/16 15:04:45 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2018 Ingo Schwarze @@ -114,7 +114,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 */ @@ -236,7 +236,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. */ @@ -355,7 +354,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) -- 2.20.1