From 8e33dc5eea79f5ee60c69d82a3a24e4d632f9e7d Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sat, 5 Apr 2025 19:39:22 +0200 Subject: Added int_diff() which checks for overflow --- FICS/ratings.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'FICS/ratings.c') diff --git a/FICS/ratings.c b/FICS/ratings.c index 8fd683c..5f06ccc 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -1304,6 +1304,18 @@ com_statistics(int p, param_list param) return COM_OK; } +/* + * Return the difference of 'a - b' + */ +PUBLIC int +int_diff(const char *fn, const int a, const int b) +{ + if ((b > 0 && a < INT_MIN + b) || + (b < 0 && a > INT_MAX + b)) + errx(1, "%s: integer overflow (%d - %d)", fn, a, b); + return (a - b); +} + PUBLIC int com_fixrank(int p, param_list param) { -- cgit v1.2.3