gtestutils: Fix a sign-conversion warning in g_assert_cmpmem()

It was assigning the two provided lengths to internal `int` variables.
Given that memory block lengths are typically a `size_t`, this will
usually result in a warning if `-Wsign-conversion` is enabled.

Given that the internal variables are passed to `memcmp()`, which takes
`size_t`, change them to `size_t` and add an explicit cast to avoid
warnings in future.

The alternative would be to mess around with defining `__l1` and `__l2`
to using `typeof()`, but that would lead to a complete mess with the
printf placeholders and probably cause more problems than it fixes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #2919
This commit is contained in:
Philip Withnall 2023-02-15 14:23:31 +00:00
parent 39eea23825
commit d2d1af284d

View File

@ -82,7 +82,7 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
} G_STMT_END
#define g_assert_cmpmem(m1, l1, m2, l2) G_STMT_START {\
gconstpointer __m1 = m1, __m2 = m2; \
int __l1 = l1, __l2 = l2; \
size_t __l1 = (size_t) l1, __l2 = (size_t) l2; \
if (__l1 != 0 && __m1 == NULL) \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #l1 " == 0 || " #m1 " != NULL)"); \