From e5409374b218c55eda9ee87cfe273254724337ec Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Mon, 18 Mar 2024 10:01:58 -0700 Subject: [PATCH] glib/gvariant: fix compile error with GCC 14.0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was erroring on recent GCC because `struct heap_dict` is smaller than the publicly provided size (guintptr[16]) in the header for GVariantDict. Port to use `g_malloc()` directly, and use a static assertion to ensure we’re allocating the larger of the two struct sizes. --- glib/gvariant.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/glib/gvariant.c b/glib/gvariant.c index 651771bad..ea99e1f22 100644 --- a/glib/gvariant.c +++ b/glib/gvariant.c @@ -3978,7 +3978,11 @@ g_variant_dict_new (GVariant *from_asv) { GVariantDict *dict; - dict = g_slice_alloc (sizeof (struct heap_dict)); + /* We actually want to treat the allocation as a `struct heap_dict`, but the + * compiler will warn if it’s not at least as big as `struct GVariantDict`. */ + G_STATIC_ASSERT (sizeof (GVariantDict) >= sizeof (struct heap_dict)); + + dict = g_malloc (sizeof (GVariantDict)); g_variant_dict_init (dict, from_asv); GVHD(dict)->magic = GVHD_MAGIC; GVHD(dict)->ref_count = 1; @@ -4331,7 +4335,7 @@ g_variant_dict_unref (GVariantDict *dict) if (--GVHD(dict)->ref_count == 0) { g_variant_dict_clear (dict); - g_slice_free (struct heap_dict, (struct heap_dict *) dict); + g_free_sized (dict, sizeof (GVariantDict)); } }