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

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

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

Visibility: public

Requested revision: fa5011aa3166ace57a1c02158b04e8025900bb56

Requested commit: fa5011aa3166ace57a1c02158b04e8025900bb56

Commit: fa5011aa3166ace57a1c02158b04e8025900bb56

Tree: 9a989a26fc3b7dd40c0a5178ac7abe56dd1496fd

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

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

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