Skip to content

Commit b265324

Browse files
nyhwkozaczuk
authored andcommitted
tests: fix warning in tst-mmap.cc
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]>
1 parent 3693d1f commit b265324

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tests/tst-mmap.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ static inline bool try_write(void *addr)
7373
static inline bool try_write(int (*func)())
7474
{
7575
catch_segv();
76-
char byte = **(volatile char**)&func;
77-
**(volatile char**)&func = byte;
76+
char byte = *(volatile char*)func;
77+
*(volatile char*)func = byte;
7878
return !caught_segv();
7979
}
8080

0 commit comments

Comments
 (0)