hxcpp
hxcpp copied to clipboard
`cpp.Pointer.ofArray` breaks empty `Bytes` comparison
var x = haxe.io.Bytes.alloc(0);
cpp.Pointer.ofArray(x.getData());
var y = haxe.io.Bytes.ofHex("");
trace(x.compare(y));
The output is 1. If the second line is removed, the output is 0 as expected. Although x.length and y.length remain at 0, in the actual Array::Memcmp implementation, length for the first argument is 1.
Here is a more stripped down sample (adapted from #1092):
function main() {
final array:Array<Int> = [];
cpp.Pointer.ofArray(array);
trace(array.length); // 1
}
cpp.Pointer.ofArray does &array[0], and the native [] operator extends the length of the array to 1. We can instead use array->Pointer() which returns the base pointer value, which is null if no array space has been allocated yet.