From: Baptiste Daroussin <bapt@freebsd.org>
To: tech@mandoc.bsd.lv
Subject: Naive patch for handling empty input
Date: Fri, 13 Oct 2023 09:30:18 +0200 [thread overview]
Message-ID: <ncotcm65ah3e2q64b5cejjk74oc2c26uueqns435r4cdolsusr@aecbtptwad72> (raw)
[-- Attachment #1: Type: text/plain, Size: 276 bytes --]
Hello,
Please find attached a naive patch to handle dealing with empty
This is probably a two naive approach, but I didn't want to come with empty
hands :D
the issue is the following:
./mandoc </dev/null
before the patch is show 3 lines
after nothing
Best regards,
Bapt
[-- Attachment #2: emptyinput.diff --]
[-- Type: text/x-diff, Size: 2183 bytes --]
Index: cgi.c
===================================================================
RCS file: /cvs/mandoc/cgi.c,v
retrieving revision 1.181
diff -u -r1.181 cgi.c
--- cgi.c 28 Apr 2023 19:11:03 -0000 1.181
+++ cgi.c 13 Oct 2023 07:28:40 -0000
@@ -919,6 +919,8 @@
mparse_readfd(mp, fd, file);
close(fd);
meta = mparse_result(mp);
+ if (meta == NULL)
+ return;
memset(&conf, 0, sizeof(conf));
conf.fragment = 1;
Index: demandoc.c
===================================================================
RCS file: /cvs/mandoc/demandoc.c,v
retrieving revision 1.34
diff -u -r1.34 demandoc.c
--- demandoc.c 14 Apr 2022 16:43:43 -0000 1.34
+++ demandoc.c 13 Oct 2023 07:28:40 -0000
@@ -127,6 +127,8 @@
mparse_readfd(mp, fd, fn);
close(fd);
meta = mparse_result(mp);
+ if (meta == NULL)
+ return;
line = 1;
col = 0;
Index: main.c
===================================================================
RCS file: /cvs/mandoc/main.c,v
retrieving revision 1.361
diff -u -r1.361 main.c
--- main.c 14 Apr 2022 16:43:43 -0000 1.361
+++ main.c 13 Oct 2023 07:28:41 -0000
@@ -983,6 +983,8 @@
mandoc_xr_reset();
meta = mparse_result(mp);
+ if (meta == NULL)
+ return;
/* Execute the out device, if it exists. */
Index: mandocd.c
===================================================================
RCS file: /cvs/mandoc/mandocd.c,v
retrieving revision 1.13
diff -u -r1.13 mandocd.c
--- mandocd.c 14 Apr 2022 16:43:44 -0000 1.13
+++ mandocd.c 13 Oct 2023 07:28:41 -0000
@@ -261,6 +261,8 @@
mparse_readfd(parser, STDIN_FILENO, "<unixfd>");
meta = mparse_result(parser);
+ if (meta == NULL)
+ return;
if (meta->macroset == MACROSET_MDOC) {
switch (outtype) {
case OUTT_ASCII:
Index: read.c
===================================================================
RCS file: /cvs/mandoc/read.c,v
retrieving revision 1.221
diff -u -r1.221 read.c
--- read.c 19 May 2022 14:48:56 -0000 1.221
+++ read.c 13 Oct 2023 07:28:41 -0000
@@ -716,6 +716,8 @@
struct roff_meta *
mparse_result(struct mparse *curp)
{
+ if (curp->line == 0)
+ return (NULL);
roff_state_reset(curp->man);
if (curp->options & MPARSE_VALIDATE) {
if (curp->man->meta.macroset == MACROSET_MDOC)
next reply other threads:[~2023-10-13 7:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-13 7:30 Baptiste Daroussin [this message]
2023-10-13 10:13 ` Ingo Schwarze
2023-10-13 10:22 ` Baptiste Daroussin
2023-10-13 11:05 ` Ingo Schwarze
2023-10-13 11:22 ` Baptiste Daroussin
2023-10-13 11:52 ` Ingo Schwarze
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=ncotcm65ah3e2q64b5cejjk74oc2c26uueqns435r4cdolsusr@aecbtptwad72 \
--to=bapt@freebsd.org \
--cc=tech@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).