aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
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
parentf016d2b0dbdc6834bc298a4e4c89ff9b583ce940 (diff)
Added int_diff() which checks for overflow
Diffstat (limited to 'FICS')
-rw-r--r--FICS/ratings.c12
-rw-r--r--FICS/ratings.h1
2 files changed, 13 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)
{
diff --git a/FICS/ratings.h b/FICS/ratings.h
index 4cf47a8..5461cd4 100644
--- a/FICS/ratings.h
+++ b/FICS/ratings.h
@@ -61,6 +61,7 @@ extern int com_hbest(int, param_list);
extern int com_hrank(int, param_list);
extern int com_rank(int, param_list);
extern int com_statistics(int, param_list);
+extern int int_diff(const char *, const int, const int);
extern int is_active(int);
extern int rating_delta(int, int, int, int, int);
extern int rating_update(int);