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/inttypes/imaxdiv.c | |
| parent | 8a620a7c60e5745f5f38aaa1547a66a2d0dc9926 (diff) | |
check for invalid integer conversions
Diffstat (limited to 'src/inttypes/imaxdiv.c')
| -rw-r--r-- | src/inttypes/imaxdiv.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/inttypes/imaxdiv.c b/src/inttypes/imaxdiv.c index 7600cfab..c007f762 100644 --- a/src/inttypes/imaxdiv.c +++ b/src/inttypes/imaxdiv.c @@ -7,6 +7,10 @@ imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom) { SIGNAL_SAFE(0); + if ((denom == 0) || (numer == INTMAX_MIN && denom == -1)) { + UNDEFINED("In call to imaxdiv(): The result of %jd / %jd is not representable as an intmax_t", numer, denom); + } + imaxdiv_t r; r.quot = numer / denom; r.rem = numer % denom; |
