public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] nptl: Use uintptr_t for address diagnostic in nptl/tst-pthread-getattr
@ 2019-07-30  8:58 Florian Weimer
  0 siblings, 0 replies; only message in thread
From: Florian Weimer @ 2019-07-30  8:58 UTC (permalink / raw)
  To: glibc-cvs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3678 bytes --]

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8a814e20d443adc460a1030fa1a66aa9ae817483

commit 8a814e20d443adc460a1030fa1a66aa9ae817483
Author: Florian Weimer <fweimer@redhat.com>
Date:   Tue Jul 30 10:35:08 2019 +0200

    nptl: Use uintptr_t for address diagnostic in nptl/tst-pthread-getattr
    
    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.

Diff:
---
 ChangeLog                  |  6 ++++++
 nptl/tst-pthread-getattr.c | 17 +++++++++--------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6099d14..a538454 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-07-30  Florian Weimer  <fweimer@redhat.com>
+
+	* nptl/tst-pthread-getattr.c (allocate_and_test): Change return
+	type to uintptr_t.  Update comment.
+	(check_stack_top): Adjust.
+
 2019-07-29  Florian Weimer  <fweimer@redhat.com>
 
 	Linux: Move declaration of getdents64 to <dirent.h>.
diff --git a/nptl/tst-pthread-getattr.c b/nptl/tst-pthread-getattr.c
index a954778..c13795c 100644
--- a/nptl/tst-pthread-getattr.c
+++ b/nptl/tst-pthread-getattr.c
@@ -41,9 +41,11 @@
 
 static size_t pagesize;
 
-/* Check if the page in which TARGET lies is accessible.  This will segfault
-   if it fails.  */
-static volatile char *
+/* Test that the page in which TARGET lies is accessible.  This will
+   segfault if the write fails.  This function has only half a page
+   of thread stack left and so should not do anything and immediately
+   return the address to which the stack reached.  */
+static volatile uintptr_t
 allocate_and_test (char *target)
 {
   volatile char *mem = (char *) &mem;
@@ -51,7 +53,7 @@ allocate_and_test (char *target)
   mem = alloca ((size_t) (mem - target));
 
   *mem = 42;
-  return mem;
+  return (uintptr_t) mem;
 }
 
 static int
@@ -84,7 +86,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 +131,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;
     }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-07-30  8:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30  8:58 [glibc] nptl: Use uintptr_t for address diagnostic in nptl/tst-pthread-getattr Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).