aboutsummaryrefslogtreecommitdiffstats
path: root/executor
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-07-24 13:29:26 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-07-24 13:29:26 +0200
commit4969639c7cdd2ed636f880a59755e6cda8907ff9 (patch)
treed76971ec5764c320912d4a4e0be9d9fc98507eb5 /executor
parent9fe4bdc5f1037a409e82299f36117030114c7b94 (diff)
executor: fix strict aliasing violations
test_copyin does bad things. Fix that. executor/test.h: In function ‘int test_copyin()’: executor/common.h:299:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] *(type*)(addr) = (type)(val); \ ^
Diffstat (limited to 'executor')
-rw-r--r--executor/test.h23
1 files changed, 16 insertions, 7 deletions
diff --git a/executor/test.h b/executor/test.h
index 74133f58b..a5bc8e8f2 100644
--- a/executor/test.h
+++ b/executor/test.h
@@ -7,15 +7,24 @@
static int test_copyin()
{
- unsigned char x[4] = {};
- STORE_BY_BITMASK(uint16, &x[1], 0x1234, 0, 0);
- if (x[0] != 0 || x[1] != 0x34 || x[2] != 0x12 || x[3] != 0) {
- printf("bad result of STORE_BY_BITMASK(0, 0): %x %x %x %x\n", x[0], x[1], x[2], x[3]);
+ static uint16 buf[3];
+ STORE_BY_BITMASK(uint16, &buf[1], 0x1234, 0, 0);
+ unsigned char x[sizeof(buf)];
+ memcpy(x, buf, sizeof(x));
+ if (x[0] != 0 || x[1] != 0 ||
+ x[2] != 0x34 || x[3] != 0x12 ||
+ x[4] != 0 || x[5] != 0) {
+ printf("bad result of STORE_BY_BITMASK(0, 0): %x %x %x %x %x %x\n",
+ x[0], x[1], x[2], x[3], x[4], x[5]);
return 1;
}
- STORE_BY_BITMASK(uint16, &x[1], 0x555a, 5, 4);
- if (x[0] != 0 || x[1] != 0x54 || x[2] != 0x13 || x[3] != 0) {
- printf("bad result of STORE_BY_BITMASK(7, 3): %x %x %x %x\n", x[0], x[1], x[2], x[3]);
+ STORE_BY_BITMASK(uint16, &buf[1], 0x555a, 5, 4);
+ memcpy(x, buf, sizeof(x));
+ if (x[0] != 0 || x[1] != 0 ||
+ x[2] != 0x54 || x[3] != 0x13 ||
+ x[4] != 0 || x[5] != 0) {
+ printf("bad result of STORE_BY_BITMASK(7, 3): %x %x %x %x %x %x\n",
+ x[0], x[1], x[2], x[3], x[4], x[5]);
return 1;
}
return 0;