]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nptl: Use uintptr_t for address diagnostic in nptl/tst-pthread-getattr fw/gcc-10-fixes
authorFlorian Weimer <fweimer@redhat.com>
Mon, 22 Jul 2019 12:02:40 +0000 (14:02 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Mon, 22 Jul 2019 12:02:40 +0000 (14:02 +0200)
Recent GCC versions warn about the attempt to return the address of a
local variable:

tst-pthread-getattr.c: In function ‘allocate_and_test’:
tst-pthread-getattr.c:54:10: error: function returns address of local variable [-Werror=return-local-addr]
   54 |   return mem;
      |          ^~~
In file included from ../include/alloca.h:3,
                 from tst-pthread-getattr.c:26:
../stdlib/alloca.h:35:23: note: declared here
   35 | # define alloca(size) __builtin_alloca (size)
      |                       ^~~~~~~~~~~~~~~~~~~~~~~
tst-pthread-getattr.c:51:9: note: in expansion of macro ‘alloca’
   51 |   mem = alloca ((size_t) (mem - target));
      |         ^~~~~~

The address itself is used in a check in the caller, so using
uintptr_t instead is reasonable.

ChangeLog
nptl/tst-pthread-getattr.c

index c6dbb2e817634ca2e8978db429acf21f31aacd8c..e30cf048b62fcdadc9661d968ae03b41e4d26fa9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-22  Florian Weimer  <fweimer@redhat.com>
+
+       * nptl/tst-pthread-getattr.c (allocate_and_test): Change return
+       type to uintptr_t.
+       (check_stack_top): Adjust.
+
 2019-07-22  Florian Weimer  <fweimer@redhat.com>
 
        * sysdeps/unix/sysv/linux/bits/socket.h [__USE_MISC]: Include
index a9547787679cb9210a12a0ef62c5fba620eaf42e..e3634ea0a7a264d1b23b998f0f680628098dfabc 100644 (file)
@@ -43,7 +43,7 @@ static size_t pagesize;
 
 /* Check if the page in which TARGET lies is accessible.  This will segfault
    if it fails.  */
-static volatile char *
+static volatile uintptr_t
 allocate_and_test (char *target)
 {
   volatile char *mem = (char *) &mem;
@@ -51,7 +51,7 @@ allocate_and_test (char *target)
   mem = alloca ((size_t) (mem - target));
 
   *mem = 42;
-  return mem;
+  return (uintptr_t) mem;
 }
 
 static int
@@ -84,7 +84,6 @@ check_stack_top (void)
 {
   struct rlimit stack_limit;
   void *stackaddr;
-  volatile void *mem;
   size_t stacksize = 0;
   int ret;
   uintptr_t pagemask = ~(pagesize - 1);
@@ -130,14 +129,14 @@ check_stack_top (void)
      stack and test access there.  It is however sufficient to simply check if
      the top page is accessible, so we target our access halfway up the top
      page.  Thanks Chris Metcalf for this idea.  */
-  mem = allocate_and_test (stackaddr + pagesize / 2);
+  uintptr_t mem = allocate_and_test (stackaddr + pagesize / 2);
 
   /* Before we celebrate, make sure we actually did test the same page.  */
-  if (((uintptr_t) stackaddr & pagemask) != ((uintptr_t) mem & pagemask))
+  if (((uintptr_t) stackaddr & pagemask) != (mem & pagemask))
     {
       printf ("We successfully wrote into the wrong page.\n"
              "Expected %#" PRIxPTR ", but got %#" PRIxPTR "\n",
-             (uintptr_t) stackaddr & pagemask, (uintptr_t) mem & pagemask);
+             (uintptr_t) stackaddr & pagemask, mem & pagemask);
 
       return 1;
     }