diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-11-23 17:25:21 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-11-23 17:25:21 +0100 |
commit | 008413754ba588e6168c3d15280181fb2c331770 (patch) | |
tree | 63230968da2a89a25c269264986ee84622de8f4a | |
parent | d3539be8f27b8cbfdfee460fe08299158f08bcd9 (diff) | |
download | busybox-w32-008413754ba588e6168c3d15280181fb2c331770.tar.gz busybox-w32-008413754ba588e6168c3d15280181fb2c331770.tar.bz2 busybox-w32-008413754ba588e6168c3d15280181fb2c331770.zip |
bc: fix comparison bug, closes 12336
function old new delta
bc_num_cmp 249 259 +10
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 5 | ||||
-rwxr-xr-x | testsuite/bc.tests | 5 |
2 files changed, 9 insertions, 1 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 92721d18f..c7246ea1a 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1465,7 +1465,10 @@ static ssize_t bc_num_cmp(BcNum *a, BcNum *b) | |||
1465 | b_int = BC_NUM_INT(b); | 1465 | b_int = BC_NUM_INT(b); |
1466 | a_int -= b_int; | 1466 | a_int -= b_int; |
1467 | 1467 | ||
1468 | if (a_int != 0) return (ssize_t) a_int; | 1468 | if (a_int != 0) { |
1469 | if (neg) return - (ssize_t) a_int; | ||
1470 | return (ssize_t) a_int; | ||
1471 | } | ||
1469 | 1472 | ||
1470 | a_max = (a->rdx > b->rdx); | 1473 | a_max = (a->rdx > b->rdx); |
1471 | if (a_max) { | 1474 | if (a_max) { |
diff --git a/testsuite/bc.tests b/testsuite/bc.tests index 3fde60a2c..179d5d2a2 100755 --- a/testsuite/bc.tests +++ b/testsuite/bc.tests | |||
@@ -187,6 +187,11 @@ testing "bc { print 1 }" \ | |||
187 | "1" \ | 187 | "1" \ |
188 | "" "{ print 1 }" | 188 | "" "{ print 1 }" |
189 | 189 | ||
190 | testing "bc comparison 1" \ | ||
191 | "bc" \ | ||
192 | "1\n" \ | ||
193 | "" "-10 < -9" | ||
194 | |||
190 | testing "bc nested loops and breaks" \ | 195 | testing "bc nested loops and breaks" \ |
191 | "bc" \ | 196 | "bc" \ |
192 | "\ | 197 | "\ |