Merge branch 'barch/glist_position_unspecified_behavior' into 'main'

fix /list/position test

See merge request GNOME/glib!2398
This commit is contained in:
Philip Withnall 2021-12-16 09:47:03 +00:00
commit 11767ed96c

View File

@ -500,25 +500,29 @@ static void
test_position (void) test_position (void)
{ {
GList *l, *ll; GList *l, *ll;
char *a = "a";
char *b = "b";
char *c = "c";
char *d = "d";
l = NULL; l = NULL;
l = g_list_append (l, "a"); l = g_list_append (l, a);
l = g_list_append (l, "b"); l = g_list_append (l, b);
l = g_list_append (l, "c"); l = g_list_append (l, c);
ll = g_list_find (l, "a"); ll = g_list_find (l, a);
g_assert_cmpint (g_list_position (l, ll), ==, 0); g_assert_cmpint (g_list_position (l, ll), ==, 0);
g_assert_cmpint (g_list_index (l, "a"), ==, 0); g_assert_cmpint (g_list_index (l, a), ==, 0);
ll = g_list_find (l, "b"); ll = g_list_find (l, b);
g_assert_cmpint (g_list_position (l, ll), ==, 1); g_assert_cmpint (g_list_position (l, ll), ==, 1);
g_assert_cmpint (g_list_index (l, "b"), ==, 1); g_assert_cmpint (g_list_index (l, b), ==, 1);
ll = g_list_find (l, "c"); ll = g_list_find (l, c);
g_assert_cmpint (g_list_position (l, ll), ==, 2); g_assert_cmpint (g_list_position (l, ll), ==, 2);
g_assert_cmpint (g_list_index (l, "c"), ==, 2); g_assert_cmpint (g_list_index (l, c), ==, 2);
ll = g_list_append (NULL, "d"); ll = g_list_append (NULL, d);
g_assert_cmpint (g_list_position (l, ll), ==, -1); g_assert_cmpint (g_list_position (l, ll), ==, -1);
g_assert_cmpint (g_list_index (l, "d"), ==, -1); g_assert_cmpint (g_list_index (l, d), ==, -1);
g_list_free (l); g_list_free (l);
g_list_free (ll); g_list_free (ll);
@ -528,7 +532,9 @@ static void
test_double_free (void) test_double_free (void)
{ {
GList *list, *link; GList *list, *link;
GList intruder = { NULL, (gpointer)0xDEADBEEF, (gpointer)0xDEADBEEF }; // Casts to size_t first ensure compilers won't warn about pointer casts that change size
// MSVC's C4312 warning with /Wp64
GList intruder = { NULL, (gpointer)(size_t)0xDEADBEEF, (gpointer)(size_t)0xDEADBEEF };
if (g_test_subprocess ()) if (g_test_subprocess ())
{ {