source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: mandoc: When calling an empty macro, do not clobber existing arguments.
Date: Sun, 21 Apr 2019 18:51:54 -0500 (EST)	[thread overview]
Message-ID: <e3fe4a6b64803131@fantadrom.bsd.lv> (raw)

Log Message:
-----------
When calling an empty macro, do not clobber existing arguments.
Fixing a bug found with the groffer(1) version 1.19 manual page
following a report from Jan Stary.

Modified Files:
--------------
    mandoc:
        roff.c
    mandoc/regress/roff/de:
        Makefile

Added Files:
-----------
    mandoc/regress/roff/de:
        empty.in
        empty.out_ascii

Revision Data
-------------
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.364
retrieving revision 1.365
diff -Lroff.c -Lroff.c -u -p -r1.364 -r1.365
--- roff.c
+++ roff.c
@@ -3841,6 +3841,11 @@ roff_userdef(ROFF_ARGS)
 	char		 *arg, *ap, *dst, *src;
 	size_t		  sz;
 
+	/* If the macro is empty, ignore it altogether. */
+
+	if (*r->current_string == '\0')
+		return ROFF_IGN;
+
 	/* Initialize a new macro stack context. */
 
 	if (++r->mstackpos == r->mstacksz) {
@@ -3888,7 +3893,7 @@ roff_userdef(ROFF_ARGS)
 	buf->sz = strlen(buf->buf) + 1;
 	*offs = 0;
 
-	return buf->sz > 1 && buf->buf[buf->sz - 2] == '\n' ?
+	return buf->buf[buf->sz - 2] == '\n' ?
 	    ROFF_REPARSE | ROFF_USERCALL : ROFF_IGN | ROFF_APPEND;
 }
 
Index: Makefile
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/roff/de/Makefile,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lregress/roff/de/Makefile -Lregress/roff/de/Makefile -u -p -r1.4 -r1.5
--- regress/roff/de/Makefile
+++ regress/roff/de/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.12 2019/02/06 20:54:28 schwarze Exp $
+# $OpenBSD: Makefile,v 1.13 2019/04/21 23:45:50 schwarze Exp $
 
-REGRESS_TARGETS	 = append cond escname factorial indir infinite startde tab
-REGRESS_TARGETS	+= TH Dd
+REGRESS_TARGETS	 = append cond empty escname factorial
+REGRESS_TARGETS	+= indir infinite startde tab TH Dd
 LINT_TARGETS	 = escname indir infinite
 
 # groff-1.22.4 defect:
--- /dev/null
+++ regress/roff/de/empty.in
@@ -0,0 +1,18 @@
+.\" $OpenBSD: empty.in,v 1.1 2019/04/21 23:45:50 schwarze Exp $
+.Dd $Mdocdate: April 21 2019 $
+.Dt DE-EMPTY 1
+.Os
+.Sh NAME
+.Nm de-empty
+.Nd empty user-defined macro with arguments
+.Sh DESCRIPTION
+initial text
+.de empty
+..
+.de real
+arg=\\$1
+.empty wrong
+arg=\\$1
+..
+.real right
+final text
--- /dev/null
+++ regress/roff/de/empty.out_ascii
@@ -0,0 +1,9 @@
+DE-EMPTY(1)                 General Commands Manual                DE-EMPTY(1)
+
+N\bNA\bAM\bME\bE
+     d\bde\be-\b-e\bem\bmp\bpt\bty\by - empty user-defined macro with arguments
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+     initial text arg=right arg=right final text
+
+OpenBSD                         April 21, 2019                         OpenBSD
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

                 reply	other threads:[~2019-04-21 23:51 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=e3fe4a6b64803131@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).