gbranden pushed a commit to branch master
in repository groff.
commit d445aee94ec25b9f21237acf8660d0104b89da0d
Author: G. Branden Robinson <[email protected]>
AuthorDate: Wed Sep 10 08:21:53 2025 -0500
src/roff/troff/node.cpp: Add validation checks.
* src/roff/troff/node.cpp: Add more `assert()`ions and validity checks
to node classes' `asciify()` member functions, eliminate unnecessary
statements, and more consistently delete node objects after
`asciify`-ing them. (The `asciify` request modifies a
macro/string/diversion--usually a diversion--in place.)
(kern_pair_node::asciify, ligature_node::asciify): `assert()` that
each of the contained nodes is not a null pointer and do not
recursively `asciify()` them if they are.
(asciify_reverse_node_list): `assert()` that macro and node pointer
arguments are not null, and return early if they are.
(dbreak_node::asciify): `assert()` that macro pointer argument is not
null, and do not call `asciify_reverse_node_list()` on it if it is.
Also drop dead store (pointless assignment) to member variable just
before deleting the object.
(break_char_node::asciify, italic_corrected_node::asciify)
(left_italic_corrected_node::asciify): `assert()` that macro pointer
argument is not null, and do not recursively `asciify()` it if it is.
Also drop dead store (pointless assignment) to member variable just
before deleting the object.
---
ChangeLog | 23 +++++++++++++++++++++++
src/roff/troff/node.cpp | 40 ++++++++++++++++++++++++++--------------
2 files changed, 49 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e7d2cf008..0d0fe83d3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2025-09-09 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/node.cpp: Add more `assert()`ions and validity
+ checks to node classes' `asciify()` member functions, eliminate
+ unnecessary statements, and more consistently delete node
+ objects after `asciify`-ing them. (The `asciify` request
+ modifies a macro/string/diversion--usually a diversion--in
+ place.)
+ (kern_pair_node::asciify, ligature_node::asciify): `assert()`
+ that each of the contained nodes is not a null pointer and do
+ not recursively `asciify()` them if they are.
+ (asciify_reverse_node_list): `assert()` that macro and node
+ pointer arguments are not null, and return early if they are.
+ (dbreak_node::asciify): `assert()` that macro pointer argument
+ is not null, and do not call `asciify_reverse_node_list()` on it
+ if it is. Also drop dead store (pointless assignment) to member
+ variable just before deleting the object.
+ (break_char_node::asciify, italic_corrected_node::asciify)
+ (left_italic_corrected_node::asciify): `assert()` that macro
+ pointer argument is not null, and do not recursively `asciify()`
+ it if it is. Also drop dead store (pointless assignment) to
+ member variable just before deleting the object.
+
2025-09-09 G. Branden Robinson <[email protected]>
* src/roff/troff/node.cpp (class charinfo_node): Make class more
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index e5bdb6100..9665d0581 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -3904,15 +3904,21 @@ void glyph_node::asciify(macro *m)
void kern_pair_node::asciify(macro *m)
{
- n1->asciify(m);
- n2->asciify(m);
+ assert(n1 != 0 /* nullptr */);
+ assert(n2 != 0 /* nullptr */);
+ if (n1 != 0 /* nullptr */)
+ n1->asciify(m);
+ if (n2 != 0 /* nullptr */)
+ n2->asciify(m);
n1 = n2 = 0 /* nullptr */;
delete this;
}
static void asciify_reverse_node_list(macro *m, node *n)
{
- if (0 /* nullptr */ == n)
+ assert(m != 0 /* nullptr */);
+ assert(n != 0 /* nullptr */);
+ if ((0 /* nullptr */ == m) || (0 /* nullptr */ == n))
return;
asciify_reverse_node_list(m, n->next);
n->asciify(m);
@@ -3920,39 +3926,45 @@ static void asciify_reverse_node_list(macro *m, node *n)
void dbreak_node::asciify(macro *m)
{
- asciify_reverse_node_list(m, none);
- none = 0 /* nullptr */;
+ assert(m != 0 /* nullptr */);
+ if (m != 0 /* nullptr */)
+ asciify_reverse_node_list(m, none);
delete this;
}
void ligature_node::asciify(macro *m)
{
- n1->asciify(m);
- n2->asciify(m);
+ assert(n1 != 0 /* nullptr */);
+ assert(n2 != 0 /* nullptr */);
+ if (n1 != 0 /* nullptr */)
+ n1->asciify(m);
+ if (n2 != 0 /* nullptr */)
+ n2->asciify(m);
n1 = n2 = 0 /* nullptr */;
delete this;
}
void break_char_node::asciify(macro *m)
{
- nodes->asciify(m);
- nodes = 0 /* nullptr */;
+ assert(nodes != 0 /* nullptr */);
+ if (nodes != 0 /* nullptr */)
+ nodes->asciify(m);
delete this;
}
void italic_corrected_node::asciify(macro *m)
{
- nodes->asciify(m);
- nodes = 0 /* nullptr */;
+ assert(nodes != 0 /* nullptr */);
+ if (nodes != 0 /* nullptr */)
+ nodes->asciify(m);
delete this;
}
void left_italic_corrected_node::asciify(macro *m)
{
- if (nodes != 0 /* nullptr */) {
+ assert(nodes != 0 /* nullptr */);
+ if (nodes != 0 /* nullptr */)
nodes->asciify(m);
- nodes = 0 /* nullptr */;
- }
delete this;
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit