Skip to content

Instantly share code, notes, and snippets.

@ericoporto
Last active July 18, 2020 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericoporto/b641286b490cd6d7107624245acc66db to your computer and use it in GitHub Desktop.
Save ericoporto/b641286b490cd6d7107624245acc66db to your computer and use it in GitHub Desktop.
Theoretical problem

When resolving script imports, the code doesn't deals with empty string imports, and relies on nullptr :

https://github.com/adventuregamestudio/ags/blob/c52217180969576717173777d8ac195dd4347047/Engine/script/cc_instance.cpp#L1591

This works because when reading script objects, empty strings (a single \0 character) are replaced by a nullptr :

https://github.com/adventuregamestudio/ags/blob/c52217180969576717173777d8ac195dd4347047/Common/script/cc_script.cpp#L39

But when writing a script object, we don't treat the nullptr case, so if you read a script object, and want to write it back to a file, this will break here :

https://github.com/adventuregamestudio/ags/blob/c52217180969576717173777d8ac195dd4347047/Common/script/cc_script.cpp#L211

A simple fix is to simply treat this case of nullptr when writing the script object :

if(imports[n]== nullptr){
    out->WriteArray("\0", 1, 1);
} else {
    out->WriteArray(imports[n], strlen(imports[n]) + 1, 1);
}

We have the empty strings in imports because currently the compiler picks up all imports and will just blank it (in Compiler/script/cs_compiler.cpp) mark the unused imports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment