bc: fix comparison bug, closes 12336
authorDenys Vlasenko <vda.linux@googlemail.com>
Sat, 23 Nov 2019 16:25:21 +0000 (17:25 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Sat, 23 Nov 2019 16:25:21 +0000 (17:25 +0100)
function                                             old     new   delta
bc_num_cmp                                           249     259     +10

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
miscutils/bc.c
testsuite/bc.tests

index 92721d18fc9212cfd31b82c0dd454394b3f445c0..c7246ea1a1610195e78de07d9e09b4e38535fcdd 100644 (file)
@@ -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) {
index 3fde60a2c9f9083e4427b500fed28ec8e6a0da98..179d5d2a24ae8199ac6d818b8f853d1a943782f1 100755 (executable)
@@ -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" \
        "\