Pass a valid pointer to pthread_setspecific to avoid GCC 11 warning.
authorMartin Sebor <msebor@redhat.com>
Wed, 28 Apr 2021 01:05:30 +0000 (19:05 -0600)
committerMartin Sebor <msebor@redhat.com>
Wed, 28 Apr 2021 01:07:49 +0000 (19:07 -0600)
nptl/tst-tsd3.c
nptl/tst-tsd4.c
sysdeps/pthread/tst-key2.c
sysdeps/pthread/tst-key3.c
sysdeps/pthread/tst-tsd1.c
sysdeps/pthread/tst-tsd2.c
sysdeps/pthread/tst-tsd5.c
sysdeps/pthread/tst-tsd6.c

index 0dd39cc..45c7e4e 100644 (file)
@@ -37,7 +37,8 @@ destr1 (void *arg)
     {
       puts ("set key2");
 
-      if (pthread_setspecific (key2, (void *) 1l) != 0)
+      /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+      if (pthread_setspecific (key2, (void *) &left) != 0)
        {
          puts ("destr1: setspecific failed");
          exit (1);
@@ -53,7 +54,8 @@ destr2 (void *arg)
     {
       puts ("set key1");
 
-      if (pthread_setspecific (key1, (void *) 1l) != 0)
+      /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+      if (pthread_setspecific (key1, (void *) &left) != 0)
        {
          puts ("destr2: setspecific failed");
          exit (1);
@@ -68,8 +70,9 @@ tf (void *arg)
   /* Let the destructors work.  */
   left = 7;
 
-  if (pthread_setspecific (key1, (void *) 1l) != 0
-      || pthread_setspecific (key2, (void *) 1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (key1, (void *) &left) != 0
+      || pthread_setspecific (key2, (void *) &left) != 0)
     {
       puts ("tf: setspecific failed");
       exit (1);
index cc1ada4..d722194 100644 (file)
@@ -34,7 +34,8 @@ destr (void *arg)
 {
   ++rounds;
 
-  if (pthread_setspecific (key, (void *) 1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (key, (void *) &rounds) != 0)
     {
       puts ("destr: setspecific failed");
       exit (1);
@@ -45,7 +46,8 @@ destr (void *arg)
 static void *
 tf (void *arg)
 {
-  if (pthread_setspecific (key, (void *) 1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (key, (void *) &rounds) != 0)
     {
       puts ("tf: setspecific failed");
       exit (1);
index 6828873..28ba547 100644 (file)
@@ -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);
index 5cf5dcf..b6cc8c4 100644 (file)
@@ -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);
index eeabfb9..37b4aef 100644 (file)
@@ -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;
     }
 
index 275bbcc..6b4ca7c 100644 (file)
@@ -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;
 
index 5f62b5a..e875863 100644 (file)
@@ -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;
index debb1dd..5f2aa42 100644 (file)
@@ -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;
     }