gbranden pushed a commit to branch master
in repository groff.
commit 64f649db296577d3c20657c1d7f863aa2b63ce60
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Jul 15 10:28:38 2024 -0500
[troff]: Fix Savannah #64301 (3/15).
* src/roff/troff/hvunits.h: Include `config.h` and `stdckdint.h`
headers.
(vunits operator -): Use `ckd_sub()` instead of primitive operation,
and throw error diagnostic if arithmetic wraps.
---
ChangeLog | 5 +++++
src/roff/troff/hvunits.h | 13 +++++++++++--
2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c3f671214..02e2aaaa0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,6 +10,11 @@
and throw error diagnostic if arithmetic wraps.
(is_valid_expression): Remove manual detection of overflow.
+ * src/roff/troff/hvunits.h: Include `config.h` and `stdckdint.h`
+ headers.
+ (vunits operator -): Use `ckd_sub()` instead of primitive
+ operation, and throw error diagnostic if arithmetic wraps.
+
2024-07-18 G. Branden Robinson <[email protected]>
* src/roff/troff/number.cpp (is_valid_term): Trivially refactor
diff --git a/src/roff/troff/hvunits.h b/src/roff/troff/hvunits.h
index c685788df..c8b56587b 100644
--- a/src/roff/troff/hvunits.h
+++ b/src/roff/troff/hvunits.h
@@ -16,6 +16,12 @@ for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdckdint.h>
+
class vunits {
int n;
public:
@@ -105,14 +111,17 @@ inline vunits operator -(const vunits & x, const vunits &
y)
{
vunits r;
r = x;
- r.n -= y.n;
+ if (ckd_sub(&r.n, r.n, y.n))
+ error("integer subtraction wrapped");
return r;
}
inline vunits operator -(const vunits & x)
{
vunits r;
- r.n = -x.n;
+ // Why? Consider -(INT_MIN) in two's complement.
+ if (ckd_mul(&r.n, x.n, -1))
+ error("integer multiplication wrapped");
return r;
}
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit