[glib: 1/3] fix /list/position test




commit cdd53b9218b0ae462a316dc6d994b80cd24ef07e
Author: Charles Barto <chbarto microsoft com>
Date:   Wed Dec 15 17:19:50 2021 -0800

    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.

 glib/tests/list.c | 26 +++++++++++++++-----------
 1 file 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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]