gbranden pushed a commit to branch master
in repository groff.

commit 7a7c693db3974c22bde0492f0a333a1a051b4b5f
Author: G. Branden Robinson <[email protected]>
AuthorDate: Thu Jul 18 21:54:54 2024 -0500

    [troff]: Fix Savannah #64301 (14/15).
    
    * src/roff/troff/number.cpp (is_valid_term): When applying the *roff `|`
      boundary-relative motion operator, remove manual detection of
      overflow, relying on `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.
---
 ChangeLog                 |  6 +++++-
 src/roff/troff/number.cpp | 21 ++++-----------------
 2 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9df66c2f6..160f1f764 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -17,7 +17,11 @@
        indicate it.  When an overflowing literal is encountered, skip
        excess digits.  This is a behavior change, albeit an esoteric
        one; evaluation of a numeric term no longer aborts in this
-       scenario.
+       scenario.  When applying the *roff `|` boundary-relative motion
+       operator, remove manual detection of overflow, relying on
+       `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.
 
        * src/roff/troff/hvunits.h: Include `config.h` and `stdckdint.h`
        headers.
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index b00ad1df6..c5f28c10f 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -412,31 +412,18 @@ static bool is_valid_term(units *u, int scaling_unit,
     tok.next();
     if (!is_valid_term(u, scaling_unit, is_parenthesized, is_mandatory))
       return false;
-    int position;
+    int tmp, position;
     position = (scaling_unit == 'v'
                ? curdiv->get_vertical_position().to_units()
                : curenv->get_input_line_position().to_units());
     // We don't permit integer wraparound with this operator.
-    if (position >= 0) {
-      if (*u < (INT_MIN + position)) {
+    if (ckd_sub(&tmp, *u, position)) {
        error("numeric overflow");
        return false;
-      }
-    }
-    else {
-      if (*u > (INT_MAX + position)) {
-       error("numeric overflow");
-       return false;
-      }
     }
-    *u -= position;
-    if (is_negative) {
-      if (*u == INT_MIN) {
-       error("numeric overflow");
-       return false;
-      }
+    *u = tmp;
+    if (is_negative)
       *u = -*u;
-    }
     return true;
   case '(':
     tok.next();

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

Reply via email to