[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 05/10: [troff]: Fix Savannah #64469 (`-o` out of bounds).
From: |
G. Branden Robinson |
Subject: |
[groff] 05/10: [troff]: Fix Savannah #64469 (`-o` out of bounds). |
Date: |
Thu, 17 Oct 2024 20:39:42 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 40644c648efc313eb818b89725787fe2a10ba773
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Oct 17 11:11:45 2024 -0500
[troff]: Fix Savannah #64469 (`-o` out of bounds).
[troff]: Better handle inapplicable or out-of-bounds (but still
numerically valid) output page selection list (`-o` argument).
* src/roff/troff/node.cpp: New global Boolean
`was_any_page_in_output_list` tracks this datum; defaults false.
(troff_output_file::trailer): When finishing up, don't write a
"trailer" grout command (and vertical motion) if no page ever began.
Insted, throw a warning in category `range`.
(real_output_file::begin_page): Make `was_any_page_in_output_list`
true if any page is written.
Fixes <https://savannah.gnu.org/bugs/?64469>. Thanks to Dave Kemper for
the report.
Exhibit:
$ echo hello | ~/groff-stable/bin/groff -o 2
grops:<standard input>:5: fatal error: 'V' command invalid before first 'p'
command
$ echo hello | ./build/test-groff -o 2 > /dev/null
$ echo hello | ./build/test-groff -o 2 -wrange > /dev/null
troff: warning: no pages in output page selection list
---
ChangeLog | 16 ++++++++++++++++
src/roff/troff/node.cpp | 19 +++++++++++++------
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index a80ec8925..f2aa87cda 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-10-17 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [troff]: Better handle inapplicable or out-of-bounds (but still
+ numerically valid) output page selection list (`-o` argument).
+
+ * src/roff/troff/node.cpp: New global Boolean
+ `was_any_page_in_output_list` tracks this datum; defaults false.
+ (troff_output_file::trailer): When finishing up, don't write a
+ "trailer" grout command (and vertical motion) if no page ever
+ began. Insted, throw a warning in category `range`.
+ (real_output_file::begin_page): Make
+ `was_any_page_in_output_list` true if any page is written.
+
+ Fixes <https://savannah.gnu.org/bugs/?64469>. Thanks to Dave
+ Kemper for the report.
+
2024-10-17 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/roff/troff/input.cpp (parse_output_page_list): Enhance
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index 74b66672a..d18d4eebe 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -73,6 +73,7 @@ tfont *make_tfont(tfont_spec &);
int image_no = 0;
static int suppression_starting_page_number = 0;
+static bool was_any_page_in_output_list = false;
#define STORE_WIDTH 1
@@ -1603,12 +1604,16 @@ troff_output_file::~troff_output_file()
void troff_output_file::trailer(vunits page_length)
{
flush_tbuf();
- if (page_length > V0) {
- put("x trailer\n");
- put('V');
- put(page_length.to_units());
- put('\n');
+ if (was_any_page_in_output_list) {
+ if (page_length > V0) {
+ put("x trailer\n");
+ put('V');
+ put(page_length.to_units());
+ put('\n');
+ }
}
+ else
+ warning(WARN_RANGE, "no pages in output page selection list");
put("x stop\n");
}
@@ -1735,8 +1740,10 @@ int real_output_file::is_printing()
void real_output_file::begin_page(int pageno, vunits page_length)
{
printing = in_output_page_list(pageno);
- if (printing)
+ if (printing) {
+ was_any_page_in_output_list = true;
really_begin_page(pageno, page_length);
+ }
}
void real_output_file::copy_file(hunits x, vunits y,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 05/10: [troff]: Fix Savannah #64469 (`-o` out of bounds).,
G. Branden Robinson <=