diff options
author | Ben Smith <binjimin@gmail.com> | 2018-10-18 14:47:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-18 14:47:40 -0700 |
commit | 9b66cdc5a92cc11c321b0068a90f6db8c24e07ff (patch) | |
tree | 6f6cfc9c7c2258da583f9c41eb0d880ab30ea308 /src/leb128.cc | |
parent | 4e226c6a5491f15593f57aaddb12efe1ee25efb1 (diff) | |
download | wabt-9b66cdc5a92cc11c321b0068a90f6db8c24e07ff.tar.gz wabt-9b66cdc5a92cc11c321b0068a90f6db8c24e07ff.tar.bz2 wabt-9b66cdc5a92cc11c321b0068a90f6db8c24e07ff.zip |
Add test for disabled opcodes in binary reader (#934)
It's easy to forget to add a check for unexpected opcodes, and it's
tedious to have to write additional tests in `test/binary/*`.
This way we can test all potentially disabled instructions at once.
Diffstat (limited to 'src/leb128.cc')
-rw-r--r-- | src/leb128.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/leb128.cc b/src/leb128.cc index 1f550b05..796c4e29 100644 --- a/src/leb128.cc +++ b/src/leb128.cc @@ -83,6 +83,17 @@ Offset WriteU32Leb128At(Stream* stream, return length; } +Offset WriteU32Leb128Raw(uint8_t* dest, uint8_t* dest_end, uint32_t value) { + uint8_t data[MAX_U32_LEB128_BYTES]; + Offset length = 0; + LEB128_LOOP_UNTIL(value == 0); + if (static_cast<Offset>(dest_end - dest) < length) { + return 0; + } + memcpy(dest, data, length); + return length; +} + Offset WriteFixedU32Leb128Raw(uint8_t* data, uint8_t* end, uint32_t value) { if (end - data < MAX_U32_LEB128_BYTES) { return 0; |