summaryrefslogtreecommitdiff
path: root/usr.bin/dc
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2012-11-06 15:46:47 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2012-11-06 15:46:47 +0000
commitfb94c61c9f9791a63d39aa71686f2b63a7ade905 (patch)
tree4cea453ee7c5981d364bffd166abab466c87bcf6 /usr.bin/dc
parent71919cda4c8d24f9b3e9119220c04d13a9281546 (diff)
For exponenttion, only warn if the fractional part of the exponent
is non-zero and avoid div by zero. Prompted by Andres Perera.
Diffstat (limited to 'usr.bin/dc')
-rw-r--r--usr.bin/dc/bcode.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c
index 5a63b9de05e..52de45ea58d 100644
--- a/usr.bin/dc/bcode.c
+++ b/usr.bin/dc/bcode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bcode.c,v 1.42 2012/03/08 08:15:37 otto Exp $ */
+/* $OpenBSD: bcode.c,v 1.43 2012/11/06 15:46:46 otto Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -1176,12 +1176,23 @@ bexp(void)
return;
}
- if (p->scale != 0)
- warnx("Runtime warning: non-zero scale in exponent");
+ if (p->scale != 0) {
+ BIGNUM *i, *f;
+ i = BN_new();
+ bn_checkp(i);
+ f = BN_new();
+ bn_checkp(f);
+ split_number(p, i, f);
+ if (!BN_is_zero(f))
+ warnx("Runtime warning: non-zero fractional part in exponent");
+ BN_free(i);
+ BN_free(f);
+ }
+
normalize(p, 0);
neg = false;
- if (BN_cmp(p->number, &zero) < 0) {
+ if (BN_is_negative(p->number)) {
neg = true;
negate(p);
scale = bmachine.scale;
@@ -1230,7 +1241,12 @@ bexp(void)
bn_checkp(ctx);
scale_number(one, r->scale + scale);
normalize(r, scale);
- bn_check(BN_div(r->number, NULL, one, r->number, ctx));
+
+ if (BN_is_zero(r->number))
+ warnx("divide by zero");
+ else
+ bn_check(BN_div(r->number, NULL, one,
+ r->number, ctx));
BN_free(one);
BN_CTX_free(ctx);
} else