# C backend: avoid memcpy when len=0 · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/1c9bb6a79de3ca52d819177fea32ce7993634e31)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 1c9bb6a79de3ca52d819177fea32ce7993634e31

Requested commit: 1c9bb6a79de3ca52d819177fea32ce7993634e31

Commit: 1c9bb6a79de3ca52d819177fea32ce7993634e31

Tree: b417567646e316854043f775ce6d5c01793153c3

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
C backend: avoid memcpy when len=0

As of Clang 18, calling memcpy() with a misaligned pointer trips UBSAN,
even if the length is zero. This unfortunately includes any call to
`@memcpy` when source or destination are undefined and the length is
zero.

This patch makes the C backend avoid calling memcpy when the length is
zero, thereby avoiding undefined behavior.

A zig1.wasm update will be needed in the llvm18 branch to activate this
code.

```

## Parents

- [956f53beb09c07925970453d4c178c6feb53ba70](https://git.cafe/gitcafe/zig/commit/956f53beb09c07925970453d4c178c6feb53ba70?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/1c9bb6a79de3ca52d819177fea32ce7993634e31?format=markdown)
