]> git.ipfire.org Git - thirdparty/make.git/commitdiff
[SV 65448] intcmp: Compare values instead of magnitudes
authorJouke Witteveen <j.witteveen@gmail.com>
Sun, 24 Mar 2024 18:08:59 +0000 (14:08 -0400)
committerPaul Smith <psmith@gnu.org>
Sun, 24 Mar 2024 18:08:59 +0000 (14:08 -0400)
* src/function.c (func_intcmp): Reverse comparison direction when
both arguments are negative.
* tests/scripts/functions/intcmp: Add tests and remove useless ones.

src/function.c
tests/scripts/functions/intcmp

index ab89d9de4c20d1c25102b2e6195c910c8a3b9e60..82a9fe26c773975887231c7c28699f88c4e4aa02 100644 (file)
@@ -1328,6 +1328,8 @@ func_intcmp (char *o, char **argv, const char *funcname UNUSED)
       cmp = (llen > rlen) - (llen < rlen);
       if (cmp == 0)
         cmp = memcmp (lnum, rnum, llen);
+      if (lsign < 0)
+        cmp *= -1;
     }
 
   argv += 2;
index 24e25b2249fe1f32d179ccf488ea2dc3f3a2bff1..57caf2fcfd8e9ed0785eba2a3b700899a695555c 100644 (file)
@@ -10,8 +10,7 @@ n = -10
 z = 0
 # Positive
 p = 888
-min = -9223372036854775808
-max = 9223372036854775807
+q = 889
 huge = 8857889956778499040639527525992734031025567913257255490371761260681427
 .RECIPEPREFIX = >
 all:
@@ -31,15 +30,39 @@ all:
 > @echo 3_1 $(intcmp $z,$p,lt,eq,gt)
 > @echo 3_2 $(intcmp $p,$z,lt,eq,gt)
 > @echo 3_3 $(intcmp $p,$p,lt,eq,gt)
-> @echo 4_0 $(intcmp $(min),$(max),lt,eq,gt)
-> @echo 4_1 $(intcmp $(max),$(min),lt,eq,gt)
-> @echo 4_2 $(intcmp $(min),$(min),lt,eq,gt)
-> @echo 4_3 $(intcmp $(max),$(max),lt,eq,gt)
-> @echo 5_0 $(intcmp -$(huge),$(huge),lt,eq,gt)
-> @echo 5_1 $(intcmp $(huge),-$(huge),lt,eq,gt)
-> @echo 5_2 $(intcmp -$(huge),-$(huge),lt,eq,gt)
-> @echo 5_3 $(intcmp +$(huge),$(huge),lt,eq,gt)
-', '', "0_1 -10\n0_2 0\n0_3 0\n0_4 888\n0_5\n0_6\n1_1\n1_2 lt\n1_3\n2_1 lt\n2_2 ge\n2_3 ge\n3_0\n3_1 lt\n3_2 gt\n3_3 eq\n4_0 lt\n4_1 gt\n4_2 eq\n4_3 eq\n5_0 lt\n5_1 gt\n5_2 eq\n5_3 eq\n");
+> @echo 3_4 $(intcmp $p,$q,lt,eq,gt)
+> @echo 3_5 $(intcmp $q,$p,lt,eq,gt)
+> @echo 3_6 $(intcmp -$p,-$q,lt,eq,gt)
+> @echo 3_7 $(intcmp -$q,-$p,lt,eq,gt)
+> @echo 4_1 $(intcmp -$(huge),$(huge),lt,eq,gt)
+> @echo 4_2 $(intcmp $(huge),-$(huge),lt,eq,gt)
+> @echo 4_3 $(intcmp -$(huge),-$(huge),lt,eq,gt)
+> @echo 4_4 $(intcmp +$(huge),$(huge),lt,eq,gt)
+', '', '0_1 -10
+0_2 0
+0_3 0
+0_4 888
+0_5
+0_6
+1_1
+1_2 lt
+1_3
+2_1 lt
+2_2 ge
+2_3 ge
+3_0
+3_1 lt
+3_2 gt
+3_3 eq
+3_4 lt
+3_5 gt
+3_6 gt
+3_7 lt
+4_1 lt
+4_2 gt
+4_3 eq
+4_4 eq
+');
 
 # Test error conditions