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>
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);
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";
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");