tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Naive patch for handling empty input
@ 2023-10-13  7:30 Baptiste Daroussin
  2023-10-13 10:13 ` Ingo Schwarze
  0 siblings, 1 reply; 6+ messages in thread
From: Baptiste Daroussin @ 2023-10-13  7:30 UTC (permalink / raw)
  To: tech

[-- 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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-10-13 11:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-13  7:30 Naive patch for handling empty input Baptiste Daroussin
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

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).