Crash when passing null to an &inout parameter

Started by
3 comments, last by donadigo 1 year, 5 months ago

Hey, wanted to report a bug that causes the compiler to crash when building a module, here's a minimal C++ example:

#include <angelscript.h>

static void Constructor(asIScriptGeneric* gen)
{
}

static void Destructor(void* mem)
{
}

int main()
{
    auto engine = asCreateScriptEngine();
    engine->SetEngineProperty(asEP_ALLOW_UNSAFE_REFERENCES, true);
    engine->RegisterObjectType("ptr<class T>", sizeof(void*), asOBJ_VALUE | asOBJ_ASHANDLE | asOBJ_TEMPLATE | asOBJ_APP_CLASS | asOBJ_APP_CLASS_CD);
    engine->RegisterObjectBehaviour("ptr<T>", asBEHAVE_CONSTRUCT, "void f(int&in, ?&inout)", asFUNCTION(Constructor), asCALL_GENERIC);
    engine->RegisterObjectBehaviour("ptr<T>", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(Destructor), asCALL_CDECL_OBJFIRST);

    auto mod = engine->GetModule("Module", asGM_ALWAYS_CREATE);
    mod->AddScriptSection("Section", "void Main() { ptr<int>(null); }");
    mod->Build();
    
    return 0;
}

It seems that passing null into an &inout parameter crashes, when it should throw a compile error that null is not a valid reference instead, This seems to happen only in a specific case where the class that contains the method is a template type. I can reproduce this on the latest rev 2807.

I'm including a patch for a possible fix: https://gist.github.com/donadigo/3d7e39ee05d97f46b2f1bfb10355a9c4.​ I'm not sure if this is the way to go but it does fix the issue while passing all tests here.

Advertisement

Hi.

Thanks for the bug report with the code for reproducing the bug and also a suggestion for a patch to fix it. I'll review this as soon as possible.

Regards,
Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks once more for providing the sample code and suggested patch. That made my life so much easier :D

I've checked in the fix in rev 2808.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thank you for such a quick fix and continued work on the engine!

This topic is closed to new replies.

Advertisement