gbranden pushed a commit to branch master
in repository groff.

commit 653d0769ab12e4b3b5ebd28fc961771ca07f8cb7
Author: Bruno Haible <[email protected]>
AuthorDate: Sat Jul 25 01:10:20 2026 +0200

    [troff]: Fix Savannah #68583.
    
    * src/roff/troff/dictionary.cpp: Preprocessor-include C "<limits.h>"
      header file for `SSIZE_MAX` symbol.
    
      (is_good_size): Avoid signed integer overflow when computing
      dictionary capacity.
    
    Fixes <https://savannah.gnu.org/bugs/?68583>.  [Problem introduced by me
    in commit 3c1fa16104, 14 April.  --GBR]
    
    [Tweaked to fit groff's code style conventions.  Sort preprocessor
    inclusions in lexicographic order where dependencies permit.
    Parenthesize formally complex expressions.  Use Clark, not GNU, brace
    style.  --GBR]
---
 ChangeLog                     | 12 ++++++++++++
 src/roff/troff/dictionary.cpp | 10 +++++++---
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c8d6e2cae..09b1bc9e9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-07-25  Bruno Haible <[email protected]>
+
+       [troff]: Fix Savannah #68583.
+
+       * src/roff/troff/dictionary.cpp: Preprocessor-include C
+       "<limits.h>" header file for `SSIZE_MAX` symbol.
+       (is_good_size): Avoid signed integer overflow when computing
+       dictionary capacity.
+
+       Fixes <https://savannah.gnu.org/bugs/?68583>.  [Problem
+       introduced by me in commit 3c1fa16104, 14 April.  --GBR]
+
 2026-07-27  Deri James  <[email protected]>
 
        [devpdf]: Revise search for URW fonts to exclude
diff --git a/src/roff/troff/dictionary.cpp b/src/roff/troff/dictionary.cpp
index ece013fc6..590c5ad03 100644
--- a/src/roff/troff/dictionary.cpp
+++ b/src/roff/troff/dictionary.cpp
@@ -24,6 +24,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include <config.h>
 #endif
 
+#include <limits.h> // SSIZE_MAX
 #include <stdio.h> // prerequisite of searchpath.h
 #include <sys/types.h> // ssize_t
 
@@ -31,7 +32,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 #include "symbol.h" // prerequisite of dictionary.h
 #include "dictionary.h"
 #include "errarg.h" // prerequisite of error.h
-#include "error.h" // prerequisite of error.h
+#include "error.h"
 
 // is 'p' a good size for a hash table
 
@@ -42,9 +43,12 @@ static bool is_good_size(ssize_t p)
   for (i = 2; i <= (p / 2); i++)
     if ((p % i) == 0)
       return false;
-  for (i = 0x100; i != 0; i <<= 8)
-    if ((i % p) <= SMALL || (i % p) > (p - SMALL))
+  for (i = 0x100; ; i <<= 8) {
+    if (((i % p) <= SMALL) || ((i % p) > (p - SMALL)))
       return false;
+    if (i > (SSIZE_MAX >> 8))
+      break;
+  }
   return true;
 }
 

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

Reply via email to