Skip to content

Conversation

@tobil4sk
Copy link
Member

@tobil4sk tobil4sk commented Jan 6, 2026

This was causing random failures in the haxe test suite: #1286 (comment)

The part where it was going wrong was here: https://github.com/HaxeFoundation/haxe/blob/3aed86e98aaa6097c3b8c9ab5c1aee5f70faa2f9/tests/unit/src/unit/TestBytes.hx#L47

The new implementation uses memcpy for this blit, which is undefined behaviour since the source and destination regions overlap. See: https://en.cppreference.com/w/cpp/string/byte/memcpy.html

If any of the following conditions is satisfied, the behavior is undefined:
[...]
- Copying takes place between objects that overlap.

std::memmove is the alternative which is safe to use for overlapping blocks: https://en.cppreference.com/w/cpp/string/byte/memmove.html. This is also what is used in the ArrayBase::Blit method:

hxcpp/src/Array.cpp

Lines 179 to 182 in 4cff17a

if (src+len < dest || dest+len<src)
memcpy(dest,src,len);
else
memmove(dest,src,len);

@Aidan63
Copy link
Contributor

Aidan63 commented Jan 6, 2026

Ah, nice catch! I forgot that memcpy wasn't safe in overlaps and wasn't thinking about that case at all.

@tobil4sk
Copy link
Member Author

tobil4sk commented Jan 7, 2026

Looks like ci got reran but just in case it comes up again, we had this failure during execution of the mac arm64 "haxe" test:

Memory exhausted.
/Users/runner/work/_temp/d85ca6f0-43ca-4142-8d9d-60a39b2041fe.sh: line 1:  5788 Trace/BPT trap: 5       bin/TestMain
 try HXCPP_GC_BIG_BLOCKS.

@Simn Simn merged commit 3dc43ab into HaxeFoundation:master Jan 7, 2026
239 of 240 checks passed
@tobil4sk tobil4sk deleted the fix/view-copy-overlap branch January 7, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants