From a2a68b630280e5d203676094ad79f46038ccba7b Mon Sep 17 00:00:00 2001 From: grepsuzette Date: Mon, 9 Nov 2020 13:07:43 +0800 Subject: [PATCH 1/2] add test for issue 933 --- test/native/tests/TestPtr.hx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/native/tests/TestPtr.hx b/test/native/tests/TestPtr.hx index c58253925..6d2f58555 100644 --- a/test/native/tests/TestPtr.hx +++ b/test/native/tests/TestPtr.hx @@ -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 ); From 7816e51de8b34b3bfcd0f16479e97c360a51051a Mon Sep 17 00:00:00 2001 From: grepsuzette Date: Mon, 9 Nov 2020 13:08:12 +0800 Subject: [PATCH 2/2] fix issue 933 --- src/Array.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Array.cpp b/src/Array.cpp index a0a2af01c..62e275b36 100644 --- a/src/Array.cpp +++ b/src/Array.cpp @@ -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