mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
Merge branch '3562-bytes-null' into 'main'
gbytes: Squash data to `NULL` if length is zero Closes #3562 See merge request GNOME/glib!4445
This commit is contained in:
commit
bfeca8c13a
@ -128,7 +128,7 @@ g_bytes_new (gconstpointer data,
|
||||
GBytesInline *bytes;
|
||||
|
||||
bytes = g_malloc (sizeof *bytes + size);
|
||||
bytes->bytes.data = data != NULL ? bytes->inline_data : NULL;
|
||||
bytes->bytes.data = (data != NULL && size > 0) ? bytes->inline_data : NULL;
|
||||
bytes->bytes.size = size;
|
||||
bytes->bytes.free_func = NULL;
|
||||
bytes->bytes.user_data = NULL;
|
||||
|
@ -457,6 +457,14 @@ test_null (void)
|
||||
|
||||
g_assert_null (data);
|
||||
g_assert_cmpuint (size, ==, 0);
|
||||
|
||||
bytes = g_bytes_new ("some data which shouldn't be touched", 0);
|
||||
g_assert_null (g_bytes_get_data (bytes, NULL));
|
||||
|
||||
data = g_bytes_unref_to_data (bytes, &size);
|
||||
|
||||
g_assert_null (data);
|
||||
g_assert_cmpuint (size, ==, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user