diff options
author | otto <otto@openbsd.org> | 2012-11-06 16:00:05 +0000 |
---|---|---|
committer | otto <otto@openbsd.org> | 2012-11-06 16:00:05 +0000 |
commit | 8e9b8cc72144b643e1f3a3b0d3c1c25acd74d403 (patch) | |
tree | f89276618dfeab4c4d8b97faabbcf085044bd65a /usr.bin/dc | |
parent | For exponenttion, only warn if the fractional part of the exponent (diff) | |
download | wireguard-openbsd-8e9b8cc72144b643e1f3a3b0d3c1c25acd74d403.tar.xz wireguard-openbsd-8e9b8cc72144b643e1f3a3b0d3c1c25acd74d403.zip |
use BN_set_negative() and BN_is_negative() instead of subtracting or
comparing to zero
Diffstat (limited to 'usr.bin/dc')
-rw-r--r-- | usr.bin/dc/bcode.c | 16 | ||||
-rw-r--r-- | usr.bin/dc/bcode.h | 4 | ||||
-rw-r--r-- | usr.bin/dc/inout.c | 8 |
3 files changed, 11 insertions, 17 deletions
diff --git a/usr.bin/dc/bcode.c b/usr.bin/dc/bcode.c index 52de45ea58d..4a56ee18d79 100644 --- a/usr.bin/dc/bcode.c +++ b/usr.bin/dc/bcode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcode.c,v 1.43 2012/11/06 15:46:46 otto Exp $ */ +/* $OpenBSD: bcode.c,v 1.44 2012/11/06 16:00:05 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -26,8 +26,6 @@ #include "extern.h" -BIGNUM zero; - /* #define DEBUGGING */ #define MAX_ARRAY_INDEX 2048 @@ -256,8 +254,6 @@ init_bmachine(bool extended_registers) if (bmachine.readstack == NULL) err(1, NULL); bmachine.obase = bmachine.ibase = 10; - BN_init(&zero); - bn_check(BN_zero(&zero)); (void)signal(SIGINT, sighandler); } @@ -427,7 +423,7 @@ get_ulong(struct number *n) void negate(struct number *n) { - bn_check(BN_sub(n->number, &zero, n->number)); + BN_set_negative(n->number, !BN_is_negative(n->number)); } static __inline void @@ -569,7 +565,7 @@ set_scale(void) n = pop_number(); if (n != NULL) { - if (BN_cmp(n->number, &zero) < 0) + if (BN_is_negative(n->number)) warnx("scale must be a nonnegative number"); else { scale = get_ulong(n); @@ -865,7 +861,7 @@ load_array(void) if (inumber == NULL) return; idx = get_ulong(inumber); - if (BN_cmp(inumber->number, &zero) < 0) + if (BN_is_negative(inumber->number)) warnx("negative idx"); else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) warnx("idx too big"); @@ -904,7 +900,7 @@ store_array(void) return; } idx = get_ulong(inumber); - if (BN_cmp(inumber->number, &zero) < 0) { + if (BN_is_negative(inumber->number)) { warnx("negative idx"); stack_free_value(value); } else if (idx == BN_MASK2 || idx > MAX_ARRAY_INDEX) { @@ -1290,7 +1286,7 @@ bsqrt(void) if (BN_is_zero(n->number)) { r = new_number(); push_number(r); - } else if (BN_cmp(n->number, &zero) < 0) + } else if (BN_is_negative(n->number)) warnx("square root of negative number"); else { scale = max(bmachine.scale, n->scale); diff --git a/usr.bin/dc/bcode.h b/usr.bin/dc/bcode.h index a6d2291c79b..ea7c2980dc9 100644 --- a/usr.bin/dc/bcode.h +++ b/usr.bin/dc/bcode.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bcode.h,v 1.5 2006/01/16 08:09:25 otto Exp $ */ +/* $OpenBSD: bcode.h,v 1.6 2012/11/06 16:00:05 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -94,5 +94,3 @@ void negate(struct number *); void split_number(const struct number *, BIGNUM *, BIGNUM *); void bmul_number(struct number *, struct number *, struct number *); - -extern BIGNUM zero; diff --git a/usr.bin/dc/inout.c b/usr.bin/dc/inout.c index c30dc9bd264..37d2ca72b5d 100644 --- a/usr.bin/dc/inout.c +++ b/usr.bin/dc/inout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: inout.c,v 1.15 2009/10/27 23:59:37 deraadt Exp $ */ +/* $OpenBSD: inout.c,v 1.16 2012/11/06 16:00:05 otto Exp $ */ /* * Copyright (c) 2003, Otto Moerbeek <otto@drijf.net> @@ -317,7 +317,7 @@ printnumber(FILE *f, const struct number *b, u_int base) i++; } sz = i; - if (BN_cmp(b->number, &zero) < 0) + if (BN_is_negative(b->number)) putcharwrap(f, '-'); for (i = 0; i < sz; i++) { p = stack_popstring(&stack); @@ -396,8 +396,8 @@ print_ascii(FILE *f, const struct number *n) v = BN_dup(n->number); bn_checkp(v); - if (BN_cmp(v, &zero) < 0) - bn_check(BN_sub(v, &zero, v)); + if (BN_is_negative(v)) + BN_set_negative(v, 0); numbits = BN_num_bytes(v) * 8; while (numbits > 0) { |