aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/ratings.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2025-04-05 19:39:22 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2025-04-05 19:39:22 +0200
commit8e33dc5eea79f5ee60c69d82a3a24e4d632f9e7d (patch)
tree009775c886b28cfae9960e3fe49b15ef010c8a3e /FICS/ratings.c
parentf016d2b0dbdc6834bc298a4e4c89ff9b583ce940 (diff)
Added int_diff() which checks for overflow
Diffstat (limited to 'FICS/ratings.c')
-rw-r--r--FICS/ratings.c12
1 files changed, 12 insertions, 0 deletions
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)
{