diff options
| author | Jonathan Marler <johnnymarler@gmail.com> | 2024-06-16 07:45:30 -0600 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-06-17 14:34:52 -0400 |
| commit | 1165e13c256cb4aeb76674c2bc34f35c6ebd375b (patch) | |
| tree | 294f03129e5c7cabfdab92adfd9fa289e8d8eb44 /test/cases/compile_errors/export_generic_function.zig | |
| parent | 455899668b620dfda40252501c748c0a983555bd (diff) | |
| download | zig-1165e13c256cb4aeb76674c2bc34f35c6ebd375b.tar.gz zig-1165e13c256cb4aeb76674c2bc34f35c6ebd375b.zip | |
wasm2c: avoid indexing null pointer triggering undefined behavior
Using zig cc to compile and run wasm2c on zig.wasm on Windows triggers
what appears to be a sanitizer crash. The FuncGen reuse array pointer is
initialized to null and at some point it's resized to a length of zero,
which triggers this code to execute:
memcpy(&self->reuse[self->reuse_i], &self->reuse[reuse_top], sizeof(uint32_t) * reuse_n);
Given the current values, this equates to:
memcpy(&(NULL)[0], &(NULL)[0], 0);
Taking the address of the first element of a null pointer doesn't trigger
any actual runtime problem, since the pointer won't be dereferenced because
were passing 0 as the length to memcpy, however, it seems that the C spec
considers indexing a null pointer to be undefined behavior even if you
don't use the resulting value (or are just taking the address of an
indexed pointer).
Diffstat (limited to 'test/cases/compile_errors/export_generic_function.zig')
0 files changed, 0 insertions, 0 deletions
