source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Do not calculate a pointer to a memory location before the
@ 2018-08-16 15:06 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2018-08-16 15:06 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-08-16 15:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-16 15:06 mandoc: Do not calculate a pointer to a memory location before the schwarze

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).