aboutsummaryrefslogtreecommitdiffstats
path: root/extension/intdiv.c
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2017-04-14 10:27:24 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2017-04-14 10:27:24 -0400
commite176d2c3808ae99e805c402ffaccf1fc937e318d (patch)
treec9c5323803dc2f9c9d8d44b596e99f4bbe31c31f /extension/intdiv.c
parent3978dea8ddf29e8185cf61d5fba897d58439cade (diff)
downloadegawk-e176d2c3808ae99e805c402ffaccf1fc937e318d.tar.gz
egawk-e176d2c3808ae99e805c402ffaccf1fc937e318d.tar.bz2
egawk-e176d2c3808ae99e805c402ffaccf1fc937e318d.zip
In the intdiv extension, division by zero now gives a warning and returns -1 instead of throwing a fatal error.
Diffstat (limited to 'extension/intdiv.c')
-rw-r--r--extension/intdiv.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/extension/intdiv.c b/extension/intdiv.c
index e3dd0eef..aa1afd18 100644
--- a/extension/intdiv.c
+++ b/extension/intdiv.c
@@ -129,8 +129,10 @@ do_intdiv(int nargs, awk_value_t *result, struct awk_ext_func *unused)
num = double_to_int(nv.num_value);
denom = double_to_int(dv.num_value);
- if (denom == 0.0)
- fatal(ext_id, _("intdiv: division by zero attempted"));
+ if (denom == 0.0) {
+ warning(ext_id, _("intdiv: division by zero attempted"));
+ return make_number(-1, result);
+ }
quotient = double_to_int(num / denom);
#ifdef HAVE_FMOD
@@ -161,8 +163,14 @@ do_intdiv(int nargs, awk_value_t *result, struct awk_ext_func *unused)
mpz_clear(numer);
return make_number(-1, result);
}
- if (mpz_sgn(denom) == 0)
- fatal(ext_id, _("intdiv: division by zero attempted"));
+ if (mpz_sgn(denom) == 0) {
+ warning(ext_id, _("intdiv: division by zero attempted"));
+ if (numer == numer_tmp)
+ mpz_clear(numer);
+ if (denom == denom_tmp)
+ mpz_clear(denom);
+ return make_number(-1, result);
+ }
/* ask gawk to allocate return values for us */
quotient = get_mpz_ptr();