gbranden pushed a commit to branch master
in repository groff.
commit b4de661250ddc0f1727b625dcc6e2faa51f668b1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Nov 21 21:53:27 2025 -0600
src/roff/troff/input.cpp: Add assertion (7/10).
* src/roff/troff/input.cpp (encode_special_character_for_device_output):
Invert sense of test and add assertion. Lift assignment out of
conditional branch since a null pointer check now guards it from
execution with an early `return`. Add assertion for impossible
situation of a special character already being defined with a null
groff `symbol` as its identifier. For `NDEBUG` builds, return early
should that eventuate, as we can't usefully call
`map_special_character_for_device_output()` with a null pointer
argument.
---
ChangeLog | 12 +++++++++++-
src/roff/troff/input.cpp | 15 +++++++++++----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b432325f9..71d738b86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,10 +1,20 @@
2025-11-19 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp (do_overstrike, do_bracket)
- (token::description): Invert sense of test and add assertion.
+ (token::description)
+ (encode_special_character_for_device_output): Invert sense of
+ test and add assertion.
(token::next): Add assertions to `\z` escape sequence handler.
(define_character, get_line_arg): Add assertion.
(token:description): Split conditional to accommodate assertion.
+ (encode_special_character_for_device_output): Lift assignment
+ out of conditional branch since a null pointer check now guards
+ it from execution with an early `return`. Add assertion for
+ impossible situation of a special character already being
+ defined with a null groff `symbol` as its identifier. For
+ `NDEBUG` builds, return early should that eventuate, as we can't
+ usefully call `map_special_character_for_device_output()` with a
+ null pointer argument.
2025-11-21 G. Branden Robinson <[email protected]>
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index b9bbf2c49..ab1445061 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -6511,11 +6511,18 @@ static void
encode_special_character_for_device_output(macro *mac)
{
const char *sc;
charinfo *ci = tok.get_charinfo(true /* required */);
- if (ci != 0 /* nullptr */) {
- sc = ci->get_symbol()->contents();
- if (sc != 0 /* nullptr */)
- map_special_character_for_device_output(mac, sc);
+ if (0 /* nullptr */ == ci) {
+ assert(0 == "attempted to encode token without charinfo for"
+ " device extension command output");
+ return;
+ }
+ sc = ci->get_symbol()->contents();
+ if (0 /* nullptr */ == sc) {
+ assert(0 == "attempted to encode token containing charinfo with"
+ " null symbol for device extension command output");
+ return;
}
+ map_special_character_for_device_output(mac, sc);
}
// In troff output, we translate the escape character to '\', but it is
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit