gatomic: Check argument width in g_atomic_pointer_compare_and_exchange()

Check that the new value is actually pointer-width, rather than (for
example) `sizeof (int)` which could happen if someone used `0` rather
than `NULL`.

Changes suggested by Simon McVittie.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #1940
This commit is contained in:
Philip Withnall 2019-11-20 12:08:46 +00:00
parent 844332ef31
commit 75cd86f00e

View File

@ -187,6 +187,7 @@ G_END_DECLS
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer)); \
__typeof__ ((oldval)) gapcae_oldval = (oldval); \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : NULL); \