Merge branch 'array_check' into 'main'

garray: Add checks to g_ptr_array_extend_and_steal

See merge request GNOME/glib!4725
This commit is contained in:
Philip Withnall
2025-08-04 10:47:04 +00:00
2 changed files with 20 additions and 0 deletions

View File

@@ -2316,6 +2316,9 @@ g_ptr_array_extend_and_steal (GPtrArray *array_to_extend,
{ {
gpointer *pdata; gpointer *pdata;
g_return_if_fail (array_to_extend != NULL);
g_return_if_fail (array != NULL);
g_ptr_array_extend (array_to_extend, array, NULL, NULL); g_ptr_array_extend (array_to_extend, array, NULL, NULL);
/* Get rid of @array without triggering the GDestroyNotify attached /* Get rid of @array without triggering the GDestroyNotify attached

View File

@@ -2299,6 +2299,23 @@ pointer_array_extend_and_steal (void)
const gsize array_size = 100; const gsize array_size = 100;
guintptr *array_test = g_malloc (array_size * sizeof (guintptr)); guintptr *array_test = g_malloc (array_size * sizeof (guintptr));
if (g_test_undefined ())
{
/* Testing degenerated cases */
ptr_array = g_ptr_array_sized_new (0);
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*assertion*!= NULL*");
g_ptr_array_extend_and_steal (NULL, ptr_array);
g_test_assert_expected_messages ();
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL,
"*assertion*!= NULL*");
g_ptr_array_extend_and_steal (ptr_array, NULL);
g_test_assert_expected_messages ();
g_ptr_array_unref (ptr_array);
}
/* Initializing array_test */ /* Initializing array_test */
for (i = 0; i < array_size; i++) for (i = 0; i < array_size; i++)
array_test[i] = i; array_test[i] = i;