aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 19:21:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-05 19:21:34 +0100
commitf381a88234c3fd05177dddceb4da604c7e9462d1 (patch)
tree5c38941f494949f13d1bc427f5eb1212aba90066
parentb3cb90124bcf1786710c200c00530fd3f213929d (diff)
downloadbusybox-f381a88234c3fd05177dddceb4da604c7e9462d1.tar.gz
bc: make division operation interruptible
function old new delta bc_num_d 564 584 +20 bc_num_r 230 245 +15 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 35/0) Total: 35 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 6dc79118a..073a113fb 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1840,12 +1840,19 @@ static BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale)
for (q = 0; (!s && n[len] != 0) || bc_num_compare(n, p, len) >= 0; ++q)
bc_num_subArrays(n, p, len);
c->num[i] = q;
+ // a=2^100000
+ // scale=40000
+ // 1/a <- without check below, this will not be interruptible
+ if (G_interrupt) {
+ s = BC_STATUS_FAILURE;
+ break;
+ }
}
bc_num_retireMul(c, scale, a->neg, b->neg);
bc_num_free(&cp);
- return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary()
+ return s;
}
static BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
@@ -1864,7 +1871,8 @@ static BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c,
}
bc_num_init(&temp, d->cap);
- bc_num_d(a, b, c, scale);
+ s = bc_num_d(a, b, c, scale);
+ if (s) goto err;
if (scale != 0) scale = ts;