[glib: 1/2] tests: Don't compare strings by pointer
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] tests: Don't compare strings by pointer
- Date: Thu, 5 Mar 2020 11:33:04 +0000 (UTC)
commit 662059d18a0e78c48e17f2c1730a56ebbc483bc3
Author: Timm Bäder <tbaeder redhat com>
Date: Wed Mar 4 14:46:43 2020 +0100
tests: Don't compare strings by pointer
clang complains about this in the form of
<source>:6:9: warning: result of comparison against a string literal is
unspecified (use an explicit string comparison function instead)
if (f == (void *)"a") {
^ ~~~~~~~~~~~
Use variables for the strings instead, which should have the same
address.
glib/tests/list.c | 19 +++++++++++--------
glib/tests/slist.c | 35 ++++++++++++++++++++---------------
2 files changed, 31 insertions(+), 23 deletions(-)
---
diff --git a/glib/tests/list.c b/glib/tests/list.c
index 0adb1bbb1..5620c244d 100644
--- a/glib/tests/list.c
+++ b/glib/tests/list.c
@@ -471,23 +471,26 @@ test_delete_link (void)
static void
test_prepend (void)
{
+ gpointer a = "a";
+ gpointer b = "b";
+ gpointer c = "c";
GList *l, *l2;
l = NULL;
- l = g_list_prepend (l, "c");
- l = g_list_prepend (l, "a");
+ l = g_list_prepend (l, c);
+ l = g_list_prepend (l, a);
- g_assert (l->data == (gpointer)"a");
- g_assert (l->next->data == (gpointer)"c");
+ g_assert (l->data == a);
+ g_assert (l->next->data == c);
g_assert (l->next->next == NULL);
l2 = l->next;
- l2 = g_list_prepend (l2, "b");
+ l2 = g_list_prepend (l2, b);
g_assert (l2->prev == l);
- g_assert (l->data == (gpointer)"a");
- g_assert (l->next->data == (gpointer)"b");
- g_assert (l->next->next->data == (gpointer)"c");
+ g_assert (l->data == a);
+ g_assert (l->next->data == b);
+ g_assert (l->next->next->data == c);
g_assert (l->next->next->next == NULL);
g_list_free (l);
diff --git a/glib/tests/slist.c b/glib/tests/slist.c
index 1f817432c..7c17573d5 100644
--- a/glib/tests/slist.c
+++ b/glib/tests/slist.c
@@ -249,6 +249,9 @@ test_slist_remove_all (void)
static void
test_slist_insert (void)
{
+ gpointer a = "a";
+ gpointer b = "b";
+ gpointer c = "c";
GSList *slist = NULL;
GSList *st;
gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
@@ -274,23 +277,23 @@ test_slist_insert (void)
g_slist_free (slist);
- slist = g_slist_insert (NULL, "a", 1);
- g_assert (slist->data == (gpointer)"a");
+ slist = g_slist_insert (NULL, a, 1);
+ g_assert (slist->data == a);
g_assert (slist->next == NULL);
g_slist_free (slist);
- slist = g_slist_append (NULL, "a");
- slist = g_slist_append (slist, "b");
- slist = g_slist_insert (slist, "c", 5);
+ slist = g_slist_append (NULL, a);
+ slist = g_slist_append (slist, b);
+ slist = g_slist_insert (slist, c, 5);
- g_assert (slist->next->next->data == (gpointer)"c");
+ g_assert (slist->next->next->data == c);
g_assert (slist->next->next->next == NULL);
g_slist_free (slist);
- slist = g_slist_append (NULL, "a");
- slist = g_slist_insert_before (slist, slist, "b");
- g_assert (slist->data == (gpointer)"b");
- g_assert (slist->next->data == (gpointer)"a");
+ slist = g_slist_append (NULL, a);
+ slist = g_slist_insert_before (slist, slist, b);
+ g_assert (slist->data == b);
+ g_assert (slist->next->data == a);
g_assert (slist->next->next == NULL);
g_slist_free (slist);
}
@@ -334,17 +337,19 @@ test_slist_position (void)
static void
test_slist_concat (void)
{
+ gpointer a = "a";
+ gpointer b = "b";
GSList *s1, *s2, *s;
- s1 = g_slist_append (NULL, "a");
- s2 = g_slist_append (NULL, "b");
+ s1 = g_slist_append (NULL, a);
+ s2 = g_slist_append (NULL, b);
s = g_slist_concat (s1, s2);
- g_assert (s->data == (gpointer)"a");
- g_assert (s->next->data == (gpointer)"b");
+ g_assert (s->data == a);
+ g_assert (s->next->data == b);
g_assert (s->next->next == NULL);
g_slist_free (s);
- s1 = g_slist_append (NULL, "a");
+ s1 = g_slist_append (NULL, a);
s = g_slist_concat (NULL, s1);
g_assert_cmpint (g_slist_length (s), ==, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]