[git commit] bc: fix comparison bug, closes 12336

Denys Vlasenko vda.linux at googlemail.com
Sat Nov 23 16:25:21 UTC 2019


commit: https://git.busybox.net/busybox/commit/?id=008413754ba588e6168c3d15280181fb2c331770
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
bc_num_cmp                                           249     259     +10

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/bc.c     | 5 ++++-
 testsuite/bc.tests | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)

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)
 	b_int = BC_NUM_INT(b);
 	a_int -= b_int;
 
-	if (a_int != 0) return (ssize_t) a_int;
+	if (a_int != 0) {
+		if (neg) return - (ssize_t) a_int;
+		return (ssize_t) a_int;
+	}
 
 	a_max = (a->rdx > b->rdx);
 	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 }" \
 	"1" \
 	"" "{ print 1 }"
 
+testing "bc comparison 1" \
+	"bc" \
+	"1\n" \
+	"" "-10 < -9"
+
 testing "bc nested loops and breaks" \
 	"bc" \
 	"\


More information about the busybox-cvs mailing list