Skip to content

Commit

Permalink
tests: fix warning in tst-mmap.cc
Browse files Browse the repository at this point in the history
When building tests, we get this warning:

tst-mmap.hh:76:19: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
   76 |     char byte = **(volatile char**)&func;
      |                   ^~~~~~~~~~~~~~~~~~~~~~

I think this code was actually wrong... func is a function pointer, not
a function, so its name already points to the function's code - there is no
reason to take &func. I'm not even sure how this works.

After this patch, the warning is gone, and the relevant test
(tst-elf-permissions.so) still passes.

Refs #976

Signed-off-by: Nadav Har'El <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
nyh authored and wkozaczuk committed Nov 28, 2019
1 parent 3693d1f commit b265324
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tests/tst-mmap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ static inline bool try_write(void *addr)
static inline bool try_write(int (*func)())
{
catch_segv();
char byte = **(volatile char**)&func;
**(volatile char**)&func = byte;
char byte = *(volatile char*)func;
*(volatile char*)func = byte;
return !caught_segv();
}

Expand Down

0 comments on commit b265324

Please sign in to comment.