groff-commit
[Top][All Lists]
Advanced

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

[groff] 07/25: [troff]: Trivially refactor (`tem` -> `position`).


From: G. Branden Robinson
Subject: [groff] 07/25: [troff]: Trivially refactor (`tem` -> `position`).
Date: Fri, 19 Jul 2024 15:12:41 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit c4f2abed96ecc1f97ccadeb76f0e694fbf68c05f
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Jul 18 21:45:12 2024 -0500

    [troff]: Trivially refactor (`tem` -> `position`).
    
    * src/roff/troff/number.cpp (is_valid_term): Trivially refactor
      implementation of boundary-relative ("absolute" [sic]) motion
      operator.  Rename `tem` to `position`, since it is the horizontal or
      vertical drawing location to be altered.  Parenthesize expressions for
      clarity.
---
 ChangeLog                 |  8 ++++++++
 src/roff/troff/number.cpp | 17 +++++++++--------
 2 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2c8245897..add8f299b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2024-07-18  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * src/roff/troff/number.cpp (is_valid_term): Trivially refactor
+       implementation of boundary-relative ("absolute" [sic]) motion
+       operator.  Rename `tem` to `position`, since it is the
+       horizontal or vertical drawing location to be altered.
+       Parenthesize expressions for clarity.
+
 2024-07-16  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        [troff]: Refactor `has_arg()` to optionally work in copy mode.
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index b4be7a6d1..30bd76956 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -424,23 +424,24 @@ 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 tem;
-    tem = (scaling_unit == 'v'
-          ? curdiv->get_vertical_position().to_units()
-          : curenv->get_input_line_position().to_units());
-    if (tem >= 0) {
-      if (*u < INT_MIN + tem) {
+    int 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)) {
        error("numeric overflow");
        return false;
       }
     }
     else {
-      if (*u > INT_MAX + tem) {
+      if (*u > (INT_MAX + position)) {
        error("numeric overflow");
        return false;
       }
     }
-    *u -= tem;
+    *u -= position;
     if (is_negative) {
       if (*u == INT_MIN) {
        error("numeric overflow");



reply via email to

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