gbranden pushed a commit to branch master
in repository groff.

commit 7e8e4c1c0a0384a7dfd532c0df6e2b282f41779f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Apr 10 04:39:53 2026 -0500

    src/roff/troff/env.cpp: Work on Savannah #68192.
    
    * src/roff/troff/env.cpp (add_hyphenation_exception_words_request):
      Catch `std::bad_alloc` exceptions from `new` operator.  Throw a fatal
      error indicating how much memory we couldn't allocate.
    
    Continues the long process of fixing Savannah #68192.
---
 ChangeLog              |  9 +++++++++
 src/roff/troff/env.cpp | 16 ++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9813c132f..b425fa840 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-04-10  G. Branden Robinson <[email protected]>
+
+       * src/roff/troff/env.cpp
+       (add_hyphenation_exception_words_request): Catch
+       `std::bad_alloc` exceptions from `new` operator.  Throw a fatal
+       error indicating how much memory we couldn't allocate.
+
+       Continues the long process of fixing Savannah #68192.
+
 2026-04-10  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/env.cpp
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 3e0190872..a5ec92da9 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3990,10 +3990,18 @@ static void add_hyphenation_exception_words_request() 
// .hw
       // internal "ordinary" character type.  Might be simpler just to
       // use vector<int>.  --GBR
       pos[npos] = 0U;
-      // C++03: new unsigned char[npos + 1]();
-      unsigned char *tem = new unsigned char[npos + 1];
-      (void) memset(tem, 0, ((npos + 1) * sizeof(unsigned char)));
-      memcpy(tem, pos, npos + 1);
+      const size_t newposbuflen = npos + 1 /* 0U terminator */;
+      unsigned char *tem = 0 /* nullptr */;
+      try {
+       // C++03: new unsigned char[newposbuflen]();
+       tem = new unsigned char[newposbuflen];
+      }
+      catch (const std::bad_alloc &e) {
+       fatal("cannot allocate %1 bytes to add hyphenation exception"
+             " word", int(newposbuflen));
+      }
+      (void) memset(tem, 0, ((newposbuflen) * sizeof(unsigned char)));
+      memcpy(tem, pos, newposbuflen);
       tem = static_cast<unsigned char *>
            (current_language->exceptions.lookup(symbol(buf), tem));
       if (tem != 0 /* nullptr */)

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

Reply via email to