Skip to content
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

add test for issue 933, + simple fix #934

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ void ArrayBase::zero(Dynamic inFirst, Dynamic inCount)

int ArrayBase::Memcmp(ArrayBase *inOther)
{
if (length == 0 && inOther->length == 0) return 0;
int bytesA = length * GetElementSize();
int bytesB = inOther->length * inOther->GetElementSize();
int common = bytesA<bytesB ? bytesA : bytesB;
Expand Down
14 changes: 14 additions & 0 deletions test/native/tests/TestPtr.hx
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,20 @@ class TestPtr extends haxe.unit.TestCase{
assertTrue( a.memcmp(a) == 0 );
}

public function testIssue933() : Void {
var a = haxe.io.Bytes.ofString("");
var b = haxe.io.Bytes.ofString("");
assertTrue( a.length == 0 );
assertTrue( b.length == 0 );
assertTrue( a.compare(b) == 0 );

// https://github.com/HaxeFoundation/hxcpp/issues/933
var foo = cpp.NativeArray.address(a.getData(), 0).constRaw;
assertTrue( a.length == 0 );
assertTrue( b.length == 0 );
assertTrue( a.compare(b) == 0 ); // issue 933 makes this fail (value is 1)
}

public function testCapacity() {
var a = [1,2,3];
assertTrue( a.capacity() < 1000 );
Expand Down