source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: Use relative offsets instead of absolute pointers for the
@ 2015-01-31  0:13 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-01-31  0:13 UTC (permalink / raw)
  To: source

Log Message:
-----------
Use relative offsets instead of absolute pointers for the terminal 
font stack.  The latter fail after the stack is grown with realloc().
Fixing an assertion failure found by jsg@ with afl some time ago 
(test case number 51).

Modified Files:
--------------
    mdocml:
        mdoc.h
        mdoc_term.c
        tbl_term.c
        term.c
        term.h

Revision Data
-------------
Index: tbl_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/tbl_term.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -Ltbl_term.c -Ltbl_term.c -u -p -r1.37 -r1.38
--- tbl_term.c
+++ tbl_term.c
@@ -414,9 +414,9 @@ tbl_number(struct termp *tp, const struc
 static void
 tbl_word(struct termp *tp, const struct tbl_dat *dp)
 {
-	const void	*prev_font;
+	int		 prev_font;
 
-	prev_font = term_fontq(tp);
+	prev_font = tp->fonti;
 	if (dp->layout->flags & TBL_CELL_BOLD)
 		term_fontpush(tp, TERMFONT_BOLD);
 	else if (dp->layout->flags & TBL_CELL_ITALIC)
Index: term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.c,v
retrieving revision 1.243
retrieving revision 1.244
diff -Lterm.c -Lterm.c -u -p -r1.243 -r1.244
--- term.c
+++ term.c
@@ -363,22 +363,14 @@ term_fontpush(struct termp *p, enum term
 	p->fontq[p->fonti] = f;
 }
 
-/* Retrieve pointer to current font. */
-const enum termfont *
-term_fontq(struct termp *p)
-{
-
-	return(&p->fontq[p->fonti]);
-}
-
 /* Flush to make the saved pointer current again. */
 void
-term_fontpopq(struct termp *p, const enum termfont *key)
+term_fontpopq(struct termp *p, int i)
 {
 
-	while (p->fonti >= 0 && key < p->fontq + p->fonti)
-		p->fonti--;
-	assert(p->fonti >= 0);
+	assert(i >= 0);
+	if (p->fonti > i)
+		p->fonti = i;
 }
 
 /* Pop one font off the stack. */
@@ -568,7 +560,7 @@ encode1(struct termp *p, int c)
 	if (p->col + 6 >= p->maxcols)
 		adjbuf(p, p->col + 6);
 
-	f = *term_fontq(p);
+	f = p->fontq[p->fonti];
 
 	if (TERMFONT_UNDER == f || TERMFONT_BI == f) {
 		p->buf[p->col++] = '_';
@@ -600,7 +592,7 @@ encode(struct termp *p, const char *word
 	 * character by character.
 	 */
 
-	if (*term_fontq(p) == TERMFONT_NONE) {
+	if (p->fontq[p->fonti] == TERMFONT_NONE) {
 		if (p->col + sz >= p->maxcols)
 			adjbuf(p, p->col + sz);
 		for (i = 0; i < sz; i++)
Index: term.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/term.h,v
retrieving revision 1.110
retrieving revision 1.111
diff -Lterm.h -Lterm.h -u -p -r1.110 -r1.111
--- term.h
+++ term.h
@@ -126,10 +126,9 @@ int		  term_vspan(const struct termp *, 
 size_t		  term_strlen(const struct termp *, const char *);
 size_t		  term_len(const struct termp *, size_t);
 
-const enum termfont *term_fontq(struct termp *);
 void		  term_fontpush(struct termp *, enum termfont);
 void		  term_fontpop(struct termp *);
-void		  term_fontpopq(struct termp *, const enum termfont *);
+void		  term_fontpopq(struct termp *, int);
 void		  term_fontrepl(struct termp *, enum termfont);
 void		  term_fontlast(struct termp *);
 
Index: mdoc.h
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc.h,v
retrieving revision 1.133
retrieving revision 1.134
diff -Lmdoc.h -Lmdoc.h -u -p -r1.133 -r1.134
--- mdoc.h
+++ mdoc.h
@@ -366,7 +366,7 @@ struct	mdoc_node {
 	enum mdoc_type	  type; /* AST node type */
 	enum mdoc_sec	  sec; /* current named section */
 	union mdoc_data	 *norm; /* normalised args */
-	const void	 *prev_font; /* before entering this node */
+	int		  prev_font; /* before entering this node */
 	/* FIXME: these can be union'd to shave a few bytes. */
 	struct mdoc_arg	 *args; /* BLOCK/ELEM */
 	struct mdoc_node *pending; /* BLOCK */
Index: mdoc_term.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/mdoc_term.c,v
retrieving revision 1.304
retrieving revision 1.305
diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.304 -r1.305
--- mdoc_term.c
+++ mdoc_term.c
@@ -307,7 +307,7 @@ print_mdoc_node(DECL_ARGS)
 	chld = 1;
 	offset = p->offset;
 	rmargin = p->rmargin;
-	n->prev_font = term_fontq(p);
+	n->prev_font = p->fonti;
 
 	memset(&npair, 0, sizeof(struct termpair));
 	npair.ppair = pair;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

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

only message in thread, other threads:[~2015-01-31  0:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-31  0:13 mdocml: Use relative offsets instead of absolute pointers for 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).