[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 04/13: [troff]: Trivially refactor (`had_overflow`).
From: |
G. Branden Robinson |
Subject: |
[groff] 04/13: [troff]: Trivially refactor (`had_overflow`). |
Date: |
Mon, 20 Nov 2023 02:11:48 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 1ddadeee250ad5a6d15313cab73b0b9be853dd86
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Nov 13 23:38:46 2023 -0600
[troff]: Trivially refactor (`had_overflow`).
* src/roff/troff/number.cpp (is_valid_expression): Boolify and rename
local variable from `overflow` to `had_overflow`.
---
ChangeLog | 5 +++++
src/roff/troff/number.cpp | 24 ++++++++++++------------
2 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dc5437135..6fbb55b25 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-11-13 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/roff/troff/number.cpp (is_valid_expression): Boolify and
+ rename local variable from `overflow` to `had_overflow`.
+
2023-11-09 Paul Eggert <eggert@cs.ucla.edu>
[libbib]: Fix bogus size diagnostic.
diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp
index 348b55726..8b4722910 100644
--- a/src/roff/troff/number.cpp
+++ b/src/roff/troff/number.cpp
@@ -296,7 +296,7 @@ static bool is_valid_expression(units *v, int scaling_unit,
if (!is_valid_term(&v2, scaling_unit, is_parenthesized,
is_mandatory))
return false;
- int overflow = 0;
+ bool had_overflow = false;
switch (op) {
case '<':
*v = *v < v2;
@@ -330,13 +330,13 @@ static bool is_valid_expression(units *v, int
scaling_unit,
case '+':
if (v2 < 0) {
if (*v < INT_MIN - v2)
- overflow = 1;
+ had_overflow = true;
}
else if (v2 > 0) {
if (*v > INT_MAX - v2)
- overflow = 1;
+ had_overflow = true;
}
- if (overflow) {
+ if (had_overflow) {
error("addition overflow");
return false;
}
@@ -345,13 +345,13 @@ static bool is_valid_expression(units *v, int
scaling_unit,
case '-':
if (v2 < 0) {
if (*v > INT_MAX + v2)
- overflow = 1;
+ had_overflow = true;
}
else if (v2 > 0) {
if (*v < INT_MIN + v2)
- overflow = 1;
+ had_overflow = true;
}
- if (overflow) {
+ if (had_overflow) {
error("subtraction overflow");
return false;
}
@@ -361,20 +361,20 @@ static bool is_valid_expression(units *v, int
scaling_unit,
if (v2 < 0) {
if (*v > 0) {
if ((unsigned)*v > -(unsigned)INT_MIN / -(unsigned)v2)
- overflow = 1;
+ had_overflow = true;
}
else if (-(unsigned)*v > INT_MAX / -(unsigned)v2)
- overflow = 1;
+ had_overflow = true;
}
else if (v2 > 0) {
if (*v > 0) {
if (*v > INT_MAX / v2)
- overflow = 1;
+ had_overflow = true;
}
else if (-(unsigned)*v > -(unsigned)INT_MIN / v2)
- overflow = 1;
+ had_overflow = true;
}
- if (overflow) {
+ if (had_overflow) {
error("multiplication overflow");
return false;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 04/13: [troff]: Trivially refactor (`had_overflow`).,
G. Branden Robinson <=