groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 24/25: [troff]: Fix Savannah #64301 (15/15).


From: G. Branden Robinson
Subject: [groff] 24/25: [troff]: Fix Savannah #64301 (15/15).
Date: Fri, 19 Jul 2024 15:12:44 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 7570fbf57040df6320709263803ba98fe8a41719
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Jul 18 22:03:19 2024 -0500

    [troff]: Fix Savannah #64301 (15/15).
    
    * src/roff/troff/number.cpp (is_valid_term): When negating a term,
      remove manual detection of negation of `INT_MIN` (guaranteed to
      overflow in a two's complement representation), relying on `ckd_mul()`
      to indicate it.
    
    Fixes <https://savannah.gnu.org/bugs/?64301>.  You have to compile GNU
    troff with the (GCC) compiler option `-ftrapv` for arithmetic to trap
    and cause a core dump.
---
 ChangeLog                 | 7 +++++++
 src/roff/troff/number.cpp | 8 +++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 160f1f764..4b734a655 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,9 @@
        `ckd_sub()` to indicate it, and store result to temporary
        variable in case it overflows and must be discarded.  Otherwise,
        copy temporary to the storage for the term being interpreted.
+       When negating a term, remove manual detection of negation of
+       `INT_MIN` (guaranteed to overflow in a two's complement
+       representation), relying on `ckd_mul()` to indicate it.
 
        * src/roff/troff/hvunits.h: Include `config.h` and `stdckdint.h`
        headers.
@@ -38,6 +41,10 @@
        of primitive operation, and throw error diagnostic if arithmetic
        wraps.
 
+       Fixes <https://savannah.gnu.org/bugs/?64301>.  You have to
+       compile GNU troff with the (GCC) compiler option `-ftrapv` for
+       arithmetic to trap and cause a core dump.
+
 2024-07-18  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/roff/troff/number.cpp (is_valid_term): Trivially refactor
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index c5f28c10f..a82a4eeda 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -464,11 +464,9 @@ static bool is_valid_term(units *u, int scaling_unit,
     else
       tok.next();
     if (is_negative) {
-      if (*u == INT_MIN) {
-       error("numeric overflow");
-       return false;
-      }
-      *u = -*u;
+      // Why?  Consider -(INT_MIN) in two's complement.
+      if (ckd_mul(u, *u, -1))
+       error("integer multiplication wrapped");
     }
     return true;
   case '.':



reply via email to

[Prev in Thread] Current Thread [Next in Thread]