From 3d474bd8c153d57233289ad4cb9615798c3c3c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 16 Apr 2024 12:05:52 +0200 Subject: [PATCH] unix: Prevent compiler optimization to ignore our memset to zero It's well known that memset may be optimized out by compilers and this is one of these cases that freebsd CI highlighted. To prevent this to happen we should use memset_explicit() but that's C23, so till we don't support that, let's re-implement that ourself making the compiler not to optimize our memset's. In theory we could just rely on C11's memset_s, but that's not working either in freebsd. --- glib/tests/unix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/glib/tests/unix.c b/glib/tests/unix.c index 6f9469cce..296a589e6 100644 --- a/glib/tests/unix.c +++ b/glib/tests/unix.c @@ -593,6 +593,10 @@ test_signal_alternate_stack (int signal) */ g_assert_cmpint (memcmp (stack_memory, zero_mem, MINSIGSTKSZ), !=, 0); + /* We need to memset again zero_mem since compiler may have optimized it out + * as we've seen in freebsd CI. + */ + memset (zero_mem, 0, MINSIGSTKSZ); memset (stack_memory, 0, MINSIGSTKSZ); g_assert_cmpmem (stack_memory, MINSIGSTKSZ, zero_mem, MINSIGSTKSZ);