source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Dynamically allocate the stack of roff(7) .ie condition values
Date: Fri, 1 Aug 2014 11:08:46 -0400 (EDT)	[thread overview]
Message-ID: <201408011508.s71F8kVj027102@krisdoz.my.domain> (raw)

Log Message:
-----------
Dynamically allocate the stack of roff(7) .ie condition values
and thus get rid of the last useless fatal error.

Modified Files:
--------------
    mdocml:
        mandoc.h
        read.c
        roff.c

Revision Data
-------------
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.149
retrieving revision 1.150
diff -Lmandoc.h -Lmandoc.h -u -p -r1.149 -r1.150
--- mandoc.h
+++ mandoc.h
@@ -165,7 +165,6 @@ enum	mandocerr {
 	MANDOCERR_BADDISP, /* NOT IMPLEMENTED: .Bd -file */
 	MANDOCERR_SO_PATH, /* NOT IMPLEMENTED: .so with absolute path or ".." */
 	MANDOCERR_SO_FAIL, /* .so request failed */
-	MANDOCERR_MEM, /* static buffer exhausted */
 
 	/* ===== system errors ===== */
 
Index: roff.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/roff.c,v
retrieving revision 1.222
retrieving revision 1.223
diff -Lroff.c -Lroff.c -u -p -r1.222 -r1.223
--- roff.c
+++ roff.c
@@ -106,11 +106,8 @@ struct	roffreg {
 
 struct	roff {
 	struct mparse	*parse; /* parse point */
-	int		 options; /* parse options */
 	struct roffnode	*last; /* leaf of stack */
-	int		 rstack[RSTACK_MAX]; /* stack of !`ie' rules */
-	char		 control; /* control character */
-	int		 rstackpos; /* position in rstack */
+	int		*rstack; /* stack of inverted `ie' values */
 	struct roffreg	*regtab; /* number registers */
 	struct roffkv	*strtab; /* user-defined strings & macros */
 	struct roffkv	*xmbtab; /* multi-byte trans table (`tr') */
@@ -122,6 +119,10 @@ struct	roff {
 	struct eqn_node	*last_eqn; /* last equation parsed */
 	struct eqn_node	*first_eqn; /* first equation parsed */
 	struct eqn_node	*eqn; /* current equation being parsed */
+	int		 options; /* parse options */
+	int		 rstacksz; /* current size limit of rstack */
+	int		 rstackpos; /* position in rstack */
+	char		 control; /* control character */
 };
 
 struct	roffnode {
@@ -420,32 +421,32 @@ roff_free1(struct roff *r)
 		r->first_tbl = tbl->next;
 		tbl_free(tbl);
 	}
-
 	r->first_tbl = r->last_tbl = r->tbl = NULL;
 
 	while (NULL != (e = r->first_eqn)) {
 		r->first_eqn = e->next;
 		eqn_free(e);
 	}
-
 	r->first_eqn = r->last_eqn = r->eqn = NULL;
 
 	while (r->last)
 		roffnode_pop(r);
 
-	roff_freestr(r->strtab);
-	roff_freestr(r->xmbtab);
-
-	r->strtab = r->xmbtab = NULL;
+	free (r->rstack);
+	r->rstack = NULL;
+	r->rstacksz = 0;
+	r->rstackpos = -1;
 
 	roff_freereg(r->regtab);
-
 	r->regtab = NULL;
 
+	roff_freestr(r->strtab);
+	roff_freestr(r->xmbtab);
+	r->strtab = r->xmbtab = NULL;
+
 	if (r->xtab)
 		for (i = 0; i < 128; i++)
 			free(r->xtab[i].p);
-
 	free(r->xtab);
 	r->xtab = NULL;
 }
@@ -1283,10 +1284,10 @@ roff_cond(ROFF_ARGS)
 	 */
 
 	if (ROFF_ie == tok) {
-		if (r->rstackpos == RSTACK_MAX - 1) {
-			mandoc_msg(MANDOCERR_MEM,
-			    r->parse, ln, ppos, NULL);
-			return(ROFF_ERR);
+		if (r->rstackpos + 1 == r->rstacksz) {
+			r->rstacksz += 16;
+			r->rstack = mandoc_reallocarray(r->rstack,
+			    r->rstacksz, sizeof(int));
 		}
 		r->rstack[++r->rstackpos] = !r->last->rule;
 	}
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -Lread.c -Lread.c -u -p -r1.76 -r1.77
--- read.c
+++ read.c
@@ -209,7 +209,6 @@ static	const char * const	mandocerrs[MAN
 	"NOT IMPLEMENTED: .Bd -file",
 	"NOT IMPLEMENTED: .so with absolute path or \"..\"",
 	".so request failed",
-	"static buffer exhausted",
 
 	/* system errors */
 	NULL,
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-08-01 15:08 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=201408011508.s71F8kVj027102@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.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).