Skip to content

Commit 2f9ecb6

Browse files
Tutez64dimensionscape
authored andcommitted
Report a cppia new with nothing to construct as a link failure.
NewExpr::link left a NEW whose type was neither an array, a host class with a constructor, nor a script class, and both paths then dereferenced the null cppiaClass: runObject when the line ran, and genCode while the JIT compiled the module. It now reports "Could not link new" and throws "Bad link", as the other link failures do. HaxeFoundation/hxcpp#1410 Fixes #25
1 parent d9e515b commit 2f9ecb6

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎Changes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ The first libhxcpp version. It is based on hxcpp 4.3 (the changes listed under 4
191191
* Added FreeBSD, OpenBSD and NetBSD hosts: they build with the system clang through the Linux toolchain, into BSD, BSD64 or BSDArm64 (hxcpp #1089)
192192
* Fixed building on Linux with musl, such as Alpine: Sys.cpp included xlocale.h, which musl doesn't have (hxcpp #1165)
193193
* Fixed HXCPP_GC_BIG_BLOCKS stalling or running out of memory once the heap passed 2 GiB: the large allocation target was computed in an int (hxcpp #1339)
194+
* Fixed a cppia script that constructs a class the host does not have crashing the process: it fails to load with Could not link new (hxcpp #1410)
194195
* Added the libhxcpp define: a build that uses the library gets -D libhxcpp=<version>. Compare it with version("x.y.z"); a plain string comparison compares text
195196
* Added separate Linux ARMv7 and ARM64 build architectures (hxcpp #1355)
196197
* Fixed AndroidCompat.cpp closing its extern "C" section in the wrong place (hxcpp #1404)

‎src/hx/cppia/Cppia.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,13 @@ struct NewExpr : public CppiaDynamicExpr
15091509
if (!type->cppiaClass && type->haxeClass.mPtr)
15101510
constructor = type->haxeClass.mPtr->mConstructArgs;
15111511

1512+
// Nothing to construct: runObject and genCode would dereference the null cppiaClass.
1513+
if (!type->arrayType && !constructor && !type->cppiaClass)
1514+
{
1515+
CPPIALOG("Could not link new %s\n", type->name.c_str());
1516+
throw "Bad link";
1517+
}
1518+
15121519
LinkExpressions(args,inModule);
15131520
return this;
15141521
}

0 commit comments

Comments
 (0)