diff options
author | Charles Barto <chbarto@microsoft.com> | 2021-12-15 17:19:50 -0800 |
---|---|---|
committer | Charles Barto <chbarto@microsoft.com> | 2021-12-15 17:19:50 -0800 |
commit | cdd53b9218b0ae462a316dc6d994b80cd24ef07e (patch) | |
tree | 1c101f05f04885b3be554b0e03c86332791c2ab4 | |
parent | 5aafb1f21f94af21648ebcb9716a70144b028cb6 (diff) | |
download | glib-cdd53b9218b0ae462a316dc6d994b80cd24ef07e.tar.gz |
fix /list/position test
This test was exploiting unspecified behavior w.r.t. the address of string
literals, It expected them to be pooled (the same literal has the same
address, at least within a TU), but MSVC does not pool by default,
leading to a failure.
-rw-r--r-- | glib/tests/list.c | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/glib/tests/list.c b/glib/tests/list.c index 5620c244d..d34f1b84a 100644 --- a/glib/tests/list.c +++ b/glib/tests/list.c @@ -500,25 +500,29 @@ static void test_position (void) { GList *l, *ll; + char *a = "a"; + char *b = "b"; + char *c = "c"; + char *d = "d"; l = NULL; - l = g_list_append (l, "a"); - l = g_list_append (l, "b"); - l = g_list_append (l, "c"); + l = g_list_append (l, a); + l = g_list_append (l, b); + 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_index (l, "a"), ==, 0); - ll = g_list_find (l, "b"); + g_assert_cmpint (g_list_index (l, a), ==, 0); + ll = g_list_find (l, b); g_assert_cmpint (g_list_position (l, ll), ==, 1); - g_assert_cmpint (g_list_index (l, "b"), ==, 1); - ll = g_list_find (l, "c"); + g_assert_cmpint (g_list_index (l, b), ==, 1); + ll = g_list_find (l, c); 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_index (l, "d"), ==, -1); + g_assert_cmpint (g_list_index (l, d), ==, -1); g_list_free (l); g_list_free (ll); |