From 67bf199254a746d76c31341a7d137c8e9ce9cacf Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Fri, 11 May 2018 22:41:22 +0200 Subject: [PATCH] Fix comparison of object. memcmp compares object as little endian, which is not what we want. --- tests/test-obj.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test-obj.h b/tests/test-obj.h index 89cf4777..115f76bb 100644 --- a/tests/test-obj.h +++ b/tests/test-obj.h @@ -91,13 +91,17 @@ static bool testobj_equal_p(const testobj_t z1, const testobj_t z2) static int testobj_cmp(const testobj_t z1, const testobj_t z2) { if (z1->n != z2->n) return z1-> n < z2->n ? -1 : 1; - return memcmp(z1->ptr, z2->ptr, z1->n*sizeof(unsigned int)); + for(unsigned int i = 0; i < z1->n; i++) { + if (z1->ptr[i] != z2->ptr[i]) + return z1->ptr[i] < z2->ptr[i] ? -1 : 1; + } + return 0; } static int testobj_cmp_ui(const testobj_t z1, unsigned int z2) { if (z1->n != 1) return z1-> n < 1 ? -1 : 1; - return memcmp(z1->ptr, &z2, sizeof(unsigned int)); + return z1->ptr[0] < z2 ? -1 : z1->ptr[0] > z2; } static void testobj_str(string_t str, const testobj_t z, bool append)