HaxeFoundation / hashlink

A virtual machine for Haxe
https://hashlink.haxe.org/
MIT License
812 stars 158 forks source link

[NIGHTLY?] Array getDyn broken #723

Open NeeEoo opened 2 weeks ago

NeeEoo commented 2 weeks ago

Unsure if this also happens in base hashlink since theres no mac build for the stable release.

but

var hello = [];
trace(hello[hello.length - 1]); // crash
hl.types.ArrayDyn.getDyn(/Users/neo/.haxeget/std/hl/types/ArrayDyn.hx:62)
$Main.main(Main.hx:13)
.init(?:1)

haxe version: 4.3.4 hashlink version: 1.14.0

yuxiaomao commented 2 weeks ago

As hello is empty, hello.length - 1 gives -1, and docs https://haxe.org/manual/std-Array.html says:

If a read access is made on a non-existing index, a target-dependent value is returned. If a write access is made with a negative index, the result is unspecified.

Tested on my machine with latest haxe and hashlink, it gives access violation at https://github.com/HaxeFoundation/haxe/blob/fe0d3e34abb5de658d160eba0b8cc126fab77edc/std/hl/types/ArrayObj.hx#L330 . It does not say what happens when read negative index, but this behavior seems expected.

Apprentice-Alchemist commented 2 weeks ago

Looking at the code for ArrayObj.getDyn it looks like returning null is the intended behavior, except that comparing UInt and Int generates OJSLt instead of OJULt.

ncannasse commented 2 weeks ago

@Yuxiao accessing an Array outside its bounds should always return null

Le jeu. 31 oct. 2024 à 12:08, Zeta @.***> a écrit :

Looking at the code for ArrayObj.getDyn it looks like returning null is the intended behavior, except that comparing UInt and Int generates OJSLt instead of OJULt.

— Reply to this email directly, view it on GitHub https://github.com/HaxeFoundation/hashlink/issues/723#issuecomment-2449594972, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHZXQBO575OHULJOA6G25TZ6IFR5AVCNFSM6AAAAABQ2LLAKCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBZGU4TIOJXGI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

yuxiaomao commented 2 weeks ago

(You're tagging the wrong people xD, there's another yuxiao s on github!) Thank you for the tips, will check!