summary refs log tree commit diff
path: root/sysdeps
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2021-04-27 19:05:30 -0600
committerMartin Sebor <msebor@redhat.com>2021-04-27 19:07:49 -0600
commitb25b06749179d8d9a891381466e323a9dd2215f9 (patch)
treed97d85f31a972340e39525545b4670ca184aacca /sysdeps
parenta1561c3bbe8e72c6e44280d1eb5e529d2da4ecd0 (diff)
downloadglibc-b25b06749179d8d9a891381466e323a9dd2215f9.tar.gz
glibc-b25b06749179d8d9a891381466e323a9dd2215f9.tar.xz
glibc-b25b06749179d8d9a891381466e323a9dd2215f9.zip
Pass a valid pointer to pthread_setspecific to avoid GCC 11 warning.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/pthread/tst-key2.c3
-rw-r--r--sysdeps/pthread/tst-key3.c2
-rw-r--r--sysdeps/pthread/tst-tsd1.c15
-rw-r--r--sysdeps/pthread/tst-tsd2.c5
-rw-r--r--sysdeps/pthread/tst-tsd5.c3
-rw-r--r--sysdeps/pthread/tst-tsd6.c3
6 files changed, 19 insertions, 12 deletions
diff --git a/sysdeps/pthread/tst-key2.c b/sysdeps/pthread/tst-key2.c
index 6828873e41..28ba547073 100644
--- a/sysdeps/pthread/tst-key2.c
+++ b/sysdeps/pthread/tst-key2.c
@@ -56,7 +56,8 @@ tf (void *arg)
 {
   pthread_key_t *key = (pthread_key_t *) arg;
 
-  if (pthread_setspecific (*key, (void *) -1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (*key, arg) != 0)
     {
       write_message ("setspecific failed\n");
       _exit (1);
diff --git a/sysdeps/pthread/tst-key3.c b/sysdeps/pthread/tst-key3.c
index 5cf5dcf06f..b6cc8c49a3 100644
--- a/sysdeps/pthread/tst-key3.c
+++ b/sysdeps/pthread/tst-key3.c
@@ -59,7 +59,7 @@ tf (void *arg)
 {
   pthread_key_t *key = (pthread_key_t *) arg;
 
-  if (pthread_setspecific (*key, (void *) -1l) != 0)
+  if (pthread_setspecific (*key, arg) != 0)
     {
       write_message ("setspecific failed\n");
       _exit (1);
diff --git a/sysdeps/pthread/tst-tsd1.c b/sysdeps/pthread/tst-tsd1.c
index eeabfb9012..37b4aef27e 100644
--- a/sysdeps/pthread/tst-tsd1.c
+++ b/sysdeps/pthread/tst-tsd1.c
@@ -27,6 +27,9 @@ do_test (void)
   pthread_key_t key1;
   pthread_key_t key2;
   void *value;
+  /* Addresses of val1 and val2 are used as arbitrary but valid pointers
+     in calls to pthread_setspecific to avoid GCC warnings.  */
+  char val1 = 0, val2 = 0;
   int result = 0;
   int err;
 
@@ -45,7 +48,7 @@ do_test (void)
       result = 1;
     }
 
-  err = pthread_setspecific (key1, (void *) -2l);
+  err = pthread_setspecific (key1, (void *) &val1);
   if (err != 0)
     {
       printf ("1st setspecific failed: %s\n", strerror (err));
@@ -58,13 +61,13 @@ do_test (void)
       puts ("2nd getspecific == NULL\n");
       result = 1;
     }
-  else if (value != (void *) -2l)
+  else if (value != (void *) &val1)
     {
-      puts ("2nd getspecific != -2l\n");
+      puts ("2nd getspecific != &val1l\n");
       result = 1;
     }
 
-  err = pthread_setspecific (key1, (void *) -3l);
+  err = pthread_setspecific (key1, (void *) &val2);
   if (err != 0)
     {
       printf ("2nd setspecific failed: %s\n", strerror (err));
@@ -77,9 +80,9 @@ do_test (void)
       puts ("3rd getspecific == NULL\n");
       result = 1;
     }
-  else if (value != (void *) -3l)
+  else if (value != (void *) &val2)
     {
-      puts ("3rd getspecific != -2l\n");
+      puts ("3rd getspecific != &val2\n");
       result = 1;
     }
 
diff --git a/sysdeps/pthread/tst-tsd2.c b/sysdeps/pthread/tst-tsd2.c
index 275bbccfdd..6b4ca7c49f 100644
--- a/sysdeps/pthread/tst-tsd2.c
+++ b/sysdeps/pthread/tst-tsd2.c
@@ -27,7 +27,7 @@ static int result;
 static void
 destr (void *arg)
 {
-  if (arg != (void *) -2l)
+  if (arg != (void *) &result)
     result = 2;
   else
     result = 0;
@@ -40,7 +40,8 @@ tf (void *arg)
   pthread_key_t key = (pthread_key_t) (long int) arg;
   int err;
 
-  err = pthread_setspecific (key, (void *) -2l);
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  err = pthread_setspecific (key, &result);
   if (err != 0)
     result = 3;
 
diff --git a/sysdeps/pthread/tst-tsd5.c b/sysdeps/pthread/tst-tsd5.c
index 5f62b5a6e8..e875863892 100644
--- a/sysdeps/pthread/tst-tsd5.c
+++ b/sysdeps/pthread/tst-tsd5.c
@@ -53,7 +53,8 @@ do_test (void)
       puts ("key_create failed");
       return 1;
     }
-  if (pthread_setspecific (k, (void *) 1) != 0)
+  /* Use an arbitrary but valid pointer as the value.  */
+  if (pthread_setspecific (k, (void *) &k) != 0)
     {
       puts ("setspecific failed");
       return 1;
diff --git a/sysdeps/pthread/tst-tsd6.c b/sysdeps/pthread/tst-tsd6.c
index debb1dd367..5f2aa42e98 100644
--- a/sysdeps/pthread/tst-tsd6.c
+++ b/sysdeps/pthread/tst-tsd6.c
@@ -17,7 +17,8 @@ tf (void *arg)
   for (int i = 0; i < NKEYS; ++i)
     {
       void *p = pthread_getspecific (keys[i]);
-      pthread_setspecific (keys[i], (void *) 7);
+      /* Use an arbitrary but valid pointer as the value.  */
+      pthread_setspecific (keys[i], (void *) keys);
       if (p != NULL)
 	res = p;
     }