glib/gbytes: Be more careful when saving a GBytes of NULL

In 1e3b010 the behaviour of `g_bytes_new (NULL, 0)` was changed; before the
`g_bytes_get_data()` would return NULL as expected, but now it returns a pointer
outside the single GBytes allocation.

This breaks the fwupd self tests as we use a GBytes of NULL to signify that
the emulation data exists, but it has no content.

Catch this case and restore the old behaviour.
This commit is contained in:
Richard Hughes 2024-11-20 13:28:25 +00:00
parent 3e87611232
commit 9ddc97314b
No known key found for this signature in database
GPG Key ID: 17ACBA8DFA970E17
2 changed files with 2 additions and 1 deletions

View File

@ -128,7 +128,7 @@ g_bytes_new (gconstpointer data,
GBytesInline *bytes;
bytes = g_malloc (sizeof *bytes + size);
bytes->bytes.data = bytes->inline_data;
bytes->bytes.data = data != NULL ? bytes->inline_data : NULL;
bytes->bytes.size = size;
bytes->bytes.free_func = NULL;
bytes->bytes.user_data = NULL;

View File

@ -451,6 +451,7 @@ test_null (void)
gsize size;
bytes = g_bytes_new (NULL, 0);
g_assert_null (g_bytes_get_data (bytes, NULL));
data = g_bytes_unref_to_data (bytes, &size);