bt_uuid_compare: return actual comparison
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 13 Aug 2019 22:34:20 +0000 (18:34 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 14 Aug 2019 22:00:59 +0000 (18:00 -0400)
Previous implementation resulted in non-equal uuid_a being flagged as
smaller than uuid_b even when it was actually bigger.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Change-Id: I00dfe935f21514d78bd586bb52729c5e147c8a36
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1912
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/common/uuid.c
tests/lib/test_bt_uuid.c

index f6d895a8914c63d34f2a64de766cf9d86698f7bc..7f817d0127085d89f03d1c706c4d0b7ae5d94b4c 100644 (file)
@@ -103,13 +103,7 @@ end:
 BT_HIDDEN
 int bt_uuid_compare(const bt_uuid_t uuid_a, const bt_uuid_t uuid_b)
 {
 BT_HIDDEN
 int bt_uuid_compare(const bt_uuid_t uuid_a, const bt_uuid_t uuid_b)
 {
-       int ret = 0;
-
-       if (memcmp(uuid_a, uuid_b, BT_UUID_LEN) != 0) {
-               ret = -1;
-       }
-
-       return ret;
+       return memcmp(uuid_a, uuid_b, BT_UUID_LEN);
 }
 
 BT_HIDDEN
 }
 
 BT_HIDDEN
index 3aef05ed8565aea0afc9cd3c9c8cd2072bbd7de6..27c870d695e8fdb654c66b22eaae3f6a16a7e541 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "common/uuid.h"
 
 
 #include "common/uuid.h"
 
-#define NR_TESTS 21
+#define NR_TESTS 23
 
 static const char valid_str_1[] = "3d260c88-75ea-47b8-a7e2-d6077c0378d9";
 static const char valid_str_2[] = "611cf3a6-a68b-4515-834f-208bc2762592";
 
 static const char valid_str_1[] = "3d260c88-75ea-47b8-a7e2-d6077c0378d9";
 static const char valid_str_2[] = "611cf3a6-a68b-4515-834f-208bc2762592";
@@ -127,6 +127,9 @@ void run_test_bt_uuid_compare(void)
        bt_uuid_from_str(valid_str_2, uuid2);
        ret = bt_uuid_compare(uuid1, uuid2);
        ok(ret != 0, "bt_uuid_compare - Compare different UUID, expect failure");
        bt_uuid_from_str(valid_str_2, uuid2);
        ret = bt_uuid_compare(uuid1, uuid2);
        ok(ret != 0, "bt_uuid_compare - Compare different UUID, expect failure");
+       ok(ret < 0, "bt_uuid_compare - Compare different UUID, expect uuid1 smaller");
+       ret = bt_uuid_compare(uuid2, uuid1);
+       ok(ret > 0, "bt_uuid_compare - Compare different UUID, expect uuid2 bigger");
 }
 
 static
 }
 
 static
This page took 0.025782 seconds and 4 git commands to generate.