diff options
author | JF Bastien <github@jfbastien.com> | 2016-05-02 18:42:02 -0700 |
---|---|---|
committer | JF Bastien <github@jfbastien.com> | 2016-05-02 18:42:02 -0700 |
commit | 40f9359713c9aff3a735901a7e3c2370559bfad8 (patch) | |
tree | d232682b1b36f3f5924dd199dba8bf7ef94b05f4 | |
parent | 757084eec25159a1f34a1a6fde7754dee18ac8b9 (diff) | |
download | binaryen-40f9359713c9aff3a735901a7e3c2370559bfad8.tar.gz binaryen-40f9359713c9aff3a735901a7e3c2370559bfad8.tar.bz2 binaryen-40f9359713c9aff3a735901a7e3c2370559bfad8.zip |
Fix alignment UB (#425)
There may be some other places which are broken, but they don't trigger ubsan right now. This is another fix for #404.
-rw-r--r-- | src/s2wasm.h | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 3efd667d5..56d96dde2 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -207,7 +207,8 @@ class S2WasmBuilder { // returns whether this is a relocation bool getConst(uint32_t* target) { if (isdigit(*s) || *s == '-') { - *target = getInt(); + int32_t val = getInt(); + memcpy(target, &val, sizeof(val)); return false; } else { // a global constant, we need to fix it up later @@ -1073,7 +1074,8 @@ class S2WasmBuilder { } else if (match(".int16")) { size_t size = raw.size(); raw.resize(size + 2); - (*(int16_t*)(&raw[size])) = getInt(); + int16_t val = getInt(); + memcpy(&raw[size], &val, sizeof(val)); zero = false; } else if (match(".int32")) { size_t size = raw.size(); @@ -1085,7 +1087,8 @@ class S2WasmBuilder { } else if (match(".int64")) { size_t size = raw.size(); raw.resize(size + 8); - (*(int64_t*)(&raw[size])) = getInt64(); + int64_t val = getInt64(); + memcpy(&raw[size], &val, sizeof(val)); zero = false; } else { break; |