gbranden pushed a commit to branch master
in repository groff.
commit 5517de594dc5dfddc827668dad12907794b4de6e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon May 11 10:18:25 2026 -0500
[grohtml]: Slightly refactor.
* src/devices/grohtml/html-text.cpp: Use ISO C++98 exceptions to handle
heap storage allocation failures. Align code style a bit more with
groff conventions. Preprocessor-include C++ "<new>" header file.
(html_text::push_para)
(html_text::do_para): Catch `std:bad_alloc` exceptions and `fatal()`
out with an attempt to describe what we were doing.
Continues the long process of fixing Savannah #68192.
---
ChangeLog | 12 ++++++++++++
src/devices/grohtml/html-text.cpp | 39 ++++++++++++++++++++++++++++++++-------
2 files changed, 44 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 60a3d55f0..8564b3cdd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-05-11 G. Branden Robinson <[email protected]>
+
+ * src/devices/grohtml/html-text.cpp: Slightly refactor. Use
+ ISO C++98 exceptions to handle heap storage allocation failures.
+ Align code style a bit more with groff conventions.
+ Preprocessor-include C++ "<new>" header file.
+ (html_text::push_para, html_text::do_para): Catch
+ `std:bad_alloc` exceptions and `fatal()` out with an attempt to
+ describe what we were doing.
+
+ Continues the long process of fixing Savannah #68192.
+
2026-05-11 Deri James <[email protected]>
[ms]: Add PDF support.
diff --git a/src/devices/grohtml/html-text.cpp
b/src/devices/grohtml/html-text.cpp
index 5dcd9633a..2be48cfbb 100644
--- a/src/devices/grohtml/html-text.cpp
+++ b/src/devices/grohtml/html-text.cpp
@@ -30,6 +30,8 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <stddef.h> // size_t: prerequisite of color.h
+#include <new> // std::bad_alloc
+
// libgroff
#include "symbol.h" // prerequisite of color.h
#include "color.h" // prerequisite of html-text.h
@@ -395,7 +397,15 @@ void html_text::do_push (tag_definition *p)
void html_text::push_para (HTML_TAG t, void *arg, html_indent *in)
{
- tag_definition *p= new tag_definition;
+ tag_definition *p = 0 /* nullptr */;
+
+ try {
+ p = new tag_definition;
+ }
+ catch (const std::bad_alloc &exc) {
+ fatal("cannot allocate storage for tag_definition object to push it"
+ " onto the HTML paragraph stack");
+ }
p->type = t;
p->arg1 = arg;
@@ -415,7 +425,16 @@ void html_text::push_para (HTML_TAG t)
void html_text::push_para (color *c)
{
- tag_definition *p = new tag_definition;
+ tag_definition *p = 0 /* nullptr */;
+
+ try {
+ p = new tag_definition;
+ }
+ catch (const std::bad_alloc &exc) {
+ fatal("cannot allocate storage for tag_definition object with color"
+ " '%1' to push it onto the HTML paragraph stack",
+ c->nm.contents());
+ }
p->type = COLOR_TAG;
p->arg1 = 0 /* nullptr */;
@@ -719,12 +738,18 @@ void html_text::do_para (simple_output *op, const char
*arg1,
int indentation_value, int page_offset,
int line_length, int space)
{
- html_indent *ind;
+ html_indent *ind = 0 /* nullptr */;
- if (indentation_value == 0)
- ind = 0 /* nullptr */;
- else
- ind = new html_indent(op, indentation_value, page_offset, line_length);
+ if (indentation_value != 0) {
+ try {
+ ind = new html_indent(op, indentation_value, page_offset,
+ line_length);
+ }
+ catch (const std::bad_alloc &exc) {
+ fatal("cannot allocate storage for html_indent object when"
+ " starting a paragraph");
+ }
+ }
do_para(arg1, ind, space);
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit