-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std.mem.copy does not work if slices overlap #382
Comments
The implementation you provided above has a couple of bugs that hadn't surfaced due to my limited testing - it's based off the snippet I sent in IRC, right? This is what I have for now:
|
The C standard (or is it POSIX?) specifications note that it is forbidden for the ranges to overlap in memcpy and they can in memmove. This is highly annoying so I am happy to see that Zig is attempting to do this right. |
I think this may actually be solved by #476 - add |
The root problem is described in #5553. This is just a symptom. |
This was solved by #14040. The new semantics of |
Zig's current implementation of std.mem.copy is this:
"The memory areas must not overlap" is a pretty lame restriction, especially since the single branch it takes to make it work either way is a low cost. So this could be:
If we want to have another function,
copyAssumeNoOverlap
with this branch optimized away, that's fine. We'd still need to add thatassert
though:Now here's the problem:
usize(slice.ptr)
does not work at compile timestd.mem.copy
should work at compile timeAt compile time we still have this concept of overlapping memory, but the way we want to check for overlapping memory doesn't work.
The text was updated successfully, but these errors were encountered: