gbranden pushed a commit to branch master
in repository groff.

commit 47391f3179d3d576988c36042603aa21b8586b4c
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Sep 29 00:46:38 2026 -0500

    [hpftodit]: Migrate to ISO C++98 `try/new/catch`.
    
    ...partially.
    
    * src/utils/hpftodit/hpftodit.cpp (hp_msl_to_ucode_name)
      (unicode_to_ucode_name): Use ISO C++98 exceptions to handle heap
      storage allocation failure, catching `std::bad_alloc`.
      Preprocessor-include C++ "<new>" header file.
    
    Continues the long process of fixing Savannah #68192.
---
 ChangeLog                       |  9 +++++++++
 src/utils/hpftodit/hpftodit.cpp | 24 ++++++++++++++++++++++--
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ce4503dc6..a2937e269 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-09-29  G. Branden Robinson <[email protected]>
+
+       * src/utils/hpftodit/hpftodit.cpp (hp_msl_to_ucode_name)
+       (unicode_to_ucode_name): Use ISO C++98 exceptions to handle heap
+       storage allocation failure, catching `std::bad_alloc`.
+       Preprocessor-include C++ "<new>" header file.
+
+       Continues the long process of fixing Savannah #68192.
+
 2026-09-29  G. Branden Robinson <[email protected]>
 
        * src/utils/hpftodit/hpftodit.cpp (hp_msl_to_ucode_name)
diff --git a/src/utils/hpftodit/hpftodit.cpp b/src/utils/hpftodit/hpftodit.cpp
index 722857374..f247d5d79 100644
--- a/src/utils/hpftodit/hpftodit.cpp
+++ b/src/utils/hpftodit/hpftodit.cpp
@@ -41,6 +41,8 @@ put filename in error messages (or fix lib)
 
 #include <getopt.h> // getopt_long()
 
+#include <new> // std::bad_alloc
+
 #include "lib.h"
 
 #include "posix.h"
@@ -1319,8 +1321,17 @@ hp_msl_to_ucode_name(int msl)
       ustr = uname_decomposed + 1;
   }
   size_t valuelen = strlen(ustr) + 1 /* possible 'u' */ + 1 /* '\0' */;
+  char *value = 0 /* nullptr */;
   // C++03: new char[valuelen]();
-  char *value = new char[valuelen];
+  try {
+    value = new char[valuelen];
+  }
+  catch (const std::bad_alloc &e) {
+    // If we're already dying of memory starvation, there's no point
+    // trying to get more for a buffer to do pretty U+10FFFF formatting.
+    fatal("cannot allocate %1 bytes to store Unicode character name"
+         " for HP MSL character code %2", valuelen, msl);
+  }
   (void) memset(value, 0, valuelen);
   (void) snprintf(value, valuelen,
                  equal(ustr, UNNAMED) ? UNNAMED : "u%s", ustr);
@@ -1350,7 +1361,16 @@ unicode_to_ucode_name(int ucode)
   }
   size_t valuelen = strlen(ustr) + 1 /* possible 'u' */ + 1 /* '\0' */;
   // C++03: new char[valuelen]();
-  char *value = new char[valuelen];
+  char *value = 0 /* nullptr */;
+  try {
+    value = new char[valuelen];
+  }
+  catch (const std::bad_alloc &e) {
+    // If we're already dying of memory starvation, there's no point
+    // trying to get more for a buffer to do pretty U+10FFFF formatting.
+    fatal("cannot allocate %1 bytes to store Unicode character name"
+         " for Unicode character code %2 decimal", valuelen, ucode);
+  }
   (void) memset(value, 0, valuelen);
   (void) snprintf(value, valuelen,
                  equal(ustr, UNNAMED) ? UNNAMED : "u%s", ustr);

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to