From 4ea4dffa7b5f9edcd44a043e69c061f748aae2d5 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 21 Apr 2019 23:51:21 +0000 Subject: 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. --- regress/roff/de/Makefile | 6 +++--- regress/roff/de/empty.in | 18 ++++++++++++++++++ regress/roff/de/empty.out_ascii | 9 +++++++++ roff.c | 9 +++++++-- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 regress/roff/de/empty.in create mode 100644 regress/roff/de/empty.out_ascii diff --git a/regress/roff/de/Makefile b/regress/roff/de/Makefile index 0d4d203f..a68656ce 100644 --- a/regress/roff/de/Makefile +++ b/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: diff --git a/regress/roff/de/empty.in b/regress/roff/de/empty.in new file mode 100644 index 00000000..decfcb51 --- /dev/null +++ b/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 diff --git a/regress/roff/de/empty.out_ascii b/regress/roff/de/empty.out_ascii new file mode 100644 index 00000000..1883fd3e --- /dev/null +++ b/regress/roff/de/empty.out_ascii @@ -0,0 +1,9 @@ +DE-EMPTY(1) General Commands Manual DE-EMPTY(1) + +NNAAMMEE + ddee--eemmppttyy - empty user-defined macro with arguments + +DDEESSCCRRIIPPTTIIOONN + initial text arg=right arg=right final text + +OpenBSD April 21, 2019 OpenBSD diff --git a/roff.c b/roff.c index dbf260a0..a1d4fca3 100644 --- a/roff.c +++ b/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.364 2019/04/21 22:48:58 schwarze Exp $ */ +/* $Id: roff.c,v 1.365 2019/04/21 23:51:21 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017-2019 Ingo Schwarze @@ -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; } -- cgit v1.2.3