diff options
| author | Jakob Kaivo <jkk@ung.org> | 2024-02-02 13:22:25 -0500 |
|---|---|---|
| committer | Jakob Kaivo <jkk@ung.org> | 2024-02-02 13:22:25 -0500 |
| commit | 68467da17d576a17e4ff96c60f581561ac0bbe88 (patch) | |
| tree | abd46d060469cd4438634c5c4ff660d2b1771c2c /src/stdlib/div.c | |
| parent | 8a620a7c60e5745f5f38aaa1547a66a2d0dc9926 (diff) | |
check for invalid integer conversions
Diffstat (limited to 'src/stdlib/div.c')
| -rw-r--r-- | src/stdlib/div.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/stdlib/div.c b/src/stdlib/div.c index 3cb2df78..ab267a53 100644 --- a/src/stdlib/div.c +++ b/src/stdlib/div.c @@ -1,3 +1,4 @@ +#include <limits.h> #include <stdlib.h> #include "_stdlib.h" @@ -8,12 +9,17 @@ div_t div(int numer, int denom) div_t d; SIGNAL_SAFE(0); + if ((denom == 0) || (numer == INT_MIN && denom == -1)) { + UNDEFINED("In call to div(): The result of %d / %d is not representable as an int", numer, denom); + } d.quot = numer / denom; d.rem = numer % denom; return d; } +CHECK_2(div_t, {0}, div, int, int) + /*** computes both the quotient and remainder of ARGUMENT(numer) divided by ARGUMENT(denom). |
