source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: Do not calculate a pointer to a memory location before the
Date: Thu, 16 Aug 2018 10:06:05 -0500 (EST)	[thread overview]
Message-ID: <c89f07062c8b4cb0@fantadrom.bsd.lv> (raw)

Log Message:
-----------
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.

Modified Files:
--------------
    mandoc:
        man_validate.c
        mdoc_validate.c

Revision Data
-------------
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.360
retrieving revision 1.361
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.360 -r1.361
--- mdoc_validate.c
+++ 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_M
 	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)
Index: man_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/man_validate.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -Lman_validate.c -Lman_validate.c -u -p -r1.134 -r1.135
--- man_validate.c
+++ 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_MA
 	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)
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2018-08-16 15:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c89f07062c8b4cb0@fantadrom.bsd.lv \
    --to=schwarze@mandoc.bsd.lv \
    --cc=source@mandoc.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).