gbranden pushed a commit to branch master
in repository groff.
commit 8fb8b7b963cb66d82e374955ec3535b698c55a88
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Oct 8 06:10:16 2026 -0500
[libdriver]: Migrate to ISO C++98 `try/new/catch`.
* src/libs/libdriver/printer.cpp (printer::load_font): Use ISO C++98
exceptions to handle heap storage allocation failure, catching
`std::bad_alloc`.
Continues the long process of fixing Savannah #68192.
---
ChangeLog | 8 ++++++++
src/libs/libdriver/printer.cpp | 26 +++++++++++++++++++++++---
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0c26571e0..fea250d7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-10-08 G. Branden Robinson <[email protected]>
+
+ * src/libs/libdriver/printer.cpp (printer::load_font)
+ (printer::find_font): Use ISO C++98 exceptions to handle heap
+ storage allocation failure, catching `std::bad_alloc`.
+
+ Continues the long process of fixing Savannah #68192.
+
2026-10-08 G. Branden Robinson <[email protected]>
* m4/groff.m4 (GROFF_G): Revise test to rebalance its
diff --git a/src/libs/libdriver/printer.cpp b/src/libs/libdriver/printer.cpp
index 2c5412211..c226d7cd1 100644
--- a/src/libs/libdriver/printer.cpp
+++ b/src/libs/libdriver/printer.cpp
@@ -27,6 +27,8 @@ with this program. If not, see
<http://www.gnu.org/licenses/>.
#include <stdio.h> // clearerr(), ferror(), fflush(), stdout
#include <string.h> // strcmp()
+#include <new> // std::bad_alloc
+
// libgroff
#include "symbol.h" // prerequisite of color.h
#include "color.h" // prerequisite of printer.h
@@ -119,7 +121,13 @@ void printer::load_font(int n, const char *nm)
nfonts = 10;
if (nfonts <= n)
nfonts = n + 1;
- font_table = new font *[nfonts];
+ try {
+ font_table = new font *[nfonts];
+ }
+ catch (const std::bad_alloc &e) {
+ fatal("cannot allocate %1 bytes to store font description",
+ sizeof(font));
+ }
for (int i = 0; i < nfonts; i++)
font_table[i] = 0 /* nullptr */;
}
@@ -129,7 +137,13 @@ void printer::load_font(int n, const char *nm)
nfonts *= 2;
if (n >= nfonts)
nfonts = n + 1;
- font_table = new font *[nfonts];
+ try {
+ font_table = new font *[nfonts];
+ }
+ catch (const std::bad_alloc &e) {
+ fatal("cannot allocate %1 bytes to store font description",
+ sizeof(font));
+ }
int i;
for (i = 0; i < old_nfonts; i++)
font_table[i] = old_font_table[i];
@@ -152,7 +166,13 @@ font *printer::find_font(const char *nm)
font *f = make_font(nm);
if (0 /* nullptr */ == f)
fatal("cannot find font '%1'", nm);
- font_list = new font_pointer_list(f, font_list);
+ try {
+ font_list = new font_pointer_list(f, font_list);
+ }
+ catch (const std::bad_alloc &e) {
+ fatal("cannot allocate %1 bytes to store font list",
+ sizeof(font_list));
+ }
return f;
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit