Skip to content

Throw on a call on a null Array<Dynamic> in cppia - #425

Open
Tutez64 wants to merge 1 commit into
openfl:mainfrom
Tutez64:fix/cppia-null-any-array
Open

Tutez64 wants to merge 1 commit into
openfl:mainfrom
Tutez64:fix/cppia-null-any-array

Conversation

@Tutez64

@Tutez64 Tutez64 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Under HXCPP_CHECK_POINTER, a call on a null array in a cppia script throws Null Object Reference: a typed array's builtins check the array first, and so do Array<Dynamic>'s element access, pop, slice and the other calls that return an object. push, contains, remove, indexOf, lastIndexOf, join, toString, sort, insert and unshift did not. They called through the null, which ended the process with a segmentation fault, both interpreted and under the JIT, since the JIT calls the same code for them.

var a:Array<Dynamic> = null;
try a.push(1) catch (e:Dynamic) trace(e); // segfault instead of Null Object Reference

ArrayBuiltinAny now checks the array with CPPIA_CHECK in these calls, as the others do, and its genCode checks it with genNullReferenceExceptionCheck once it has it, as the typed arrays' code does. Without HXCPP_CHECK_POINTER, nothing changes.

Tests: test/regression/CppiaNullDynamicArray calls each of them, plus pop and an element read, on a null Array<Dynamic>, interpreted and then under the JIT. Before, the first call ended the host. All test/regression/Cppia* cases pass.

Under HXCPP_CHECK_POINTER, a call on a null array in a cppia script
throws Null Object Reference: a typed array's builtins check the array
first, and so do Array<Dynamic>'s element access, pop, slice and the
other calls that return an object. push, contains, remove, indexOf,
lastIndexOf, join, toString, sort, insert and unshift did not, and
called through the null, which ended the process, interpreted and under
the JIT alike, since the JIT calls the same code for them. They check it
as the others do, and the JIT checks the array once it has it, as the
typed arrays' code does.

Tests: test/regression/CppiaNullDynamicArray calls each of them on a
null Array<Dynamic>, interpreted and under the JIT. Before, the first
call ended the host with a segmentation fault.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MRK2009

MRK2009 commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

It got conflicted.

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.

2 participants