[PATCH] tests: fix warning in tst-mmap.cc

7 views
Skip to first unread message

Nadav Har'El

unread,
Nov 28, 2019, 3:27:27 AM11/28/19
to osv...@googlegroups.com, Nadav Har'El
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 <n...@scylladb.com>
---
tests/tst-mmap.hh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/tst-mmap.hh b/tests/tst-mmap.hh
index fed718ca..dcd2ea5d 100644
--- a/tests/tst-mmap.hh
+++ b/tests/tst-mmap.hh
@@ -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();
}

--
2.21.0

Commit Bot

unread,
Nov 28, 2019, 10:02:32 AM11/28/19
to osv...@googlegroups.com, Nadav Har'El
From: Nadav Har'El <n...@scylladb.com>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

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 <n...@scylladb.com>
Message-Id: <201911280827...@scylladb.com>

---
diff --git a/tests/tst-mmap.hh b/tests/tst-mmap.hh
Reply all
Reply to author
Forward
0 new messages