From: Nadav Har'El <[email protected]>
Committer: Waldemar Kozaczuk <[email protected]>
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 <[email protected]>
Message-Id: <[email protected]>

---
diff --git a/tests/tst-mmap.hh b/tests/tst-mmap.hh
--- 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();
 }

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/00000000000001e346059869670e%40google.com.

Reply via email to