summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2021-11-10 04:39:17 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2021-11-10 04:39:17 +0000
commit194fa63b057768f5e2758e90c6a08ca2ea8170a1 (patch)
tree16d7d293f6d34278208947e9afc58968b6688494 /usr.bin
parentf9e4a5f5b963dc7a988643dbc069dc76189e1ad4 (diff)
Move two BIGNUMs in printnumber() from the stack to the heap to
prepare bc(1) and dc(1) for opaque BIGNUMs. "looks sane" otto
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/dc/inout.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/usr.bin/dc/inout.c b/usr.bin/dc/inout.c
index ddd061cef5e..5995f608b2f 100644
--- a/usr.bin/dc/inout.c
+++ b/usr.bin/dc/inout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inout.c,v 1.21 2017/11/29 19:12:48 otto Exp $ */
+/* $OpenBSD: inout.c,v 1.22 2021/11/10 04:39:16 tb Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@@ -328,19 +328,21 @@ printnumber(FILE *f, const struct number *b, u_int base)
stack_clear(&stack);
if (b->scale > 0) {
struct number *num_base;
- BIGNUM mult, stop;
+ BIGNUM *mult, *stop;
putcharwrap(f, '.');
num_base = new_number();
bn_check(BN_set_word(num_base->number, base));
- BN_init(&mult);
- bn_check(BN_one(&mult));
- BN_init(&stop);
- bn_check(BN_one(&stop));
- scale_number(&stop, b->scale);
+ mult = BN_new();
+ bn_checkp(mult);
+ bn_check(BN_one(mult));
+ stop = BN_new();
+ bn_checkp(stop);
+ bn_check(BN_one(stop));
+ scale_number(stop, b->scale);
i = 0;
- while (BN_cmp(&mult, &stop) < 0) {
+ while (BN_cmp(mult, stop) < 0) {
u_long rem;
if (i && base > 16)
@@ -358,11 +360,11 @@ printnumber(FILE *f, const struct number *b, u_int base)
int_part->number));
printwrap(f, p);
free(p);
- bn_check(BN_mul_word(&mult, base));
+ bn_check(BN_mul_word(mult, base));
}
free_number(num_base);
- BN_free(&mult);
- BN_free(&stop);
+ BN_free(mult);
+ BN_free(stop);
}
flushwrap(f);
free_number(int_part);