SaladDais / tailslide

Embeddable parser, AST, tree walker and compiler for the Linden Scripting Language based on LSLint
MIT License
6 stars 1 forks source link

LL's compiler allows duplicating identifiers over 255 bytes #12

Closed SaladDais closed 2 years ago

SaladDais commented 2 years ago

Found by the lscript<->tailslide conformance fuzzer.

This compiles with LL's compiler but doesn't in tailslide:

default {state_entry() {
string asdadsadafwqafqwfafwadwawadasasdsadsadasdsadsadsadasdasdasdsadsadadwqdqd2qdq2fqfqfqdqdqasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = "foobar";
string asdadsadafwqafqwfafwadwawadasasdsadsadasdsadsadsadasdasdasdsadsadadwqdqd2qdq2fqfqfqdqdqasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = "foo";
string asdadsadafwqafqwfafwadwawadasasdsadsadasdsadsadsadasdasdasdsadsadadwqdqd2qdq2fqfqfqdqdqasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = "foo";
llOwnerSay((string)llGetFreeMemory());
}}

Seems to be due to LL relying on string literals being interned by the LLStringTable::addStringEntry, but it it treats every string over 256 chars as a distinct string due to

if (!strncmp(ret_val, str, MAX_STRINGS_LENGTH))
{
    entry->incCount();
    return entry;
}
// adds string to table

You can have colliding globals in mono as well, but it fails to start up due to the name collisions.

Since the string interning fails, all later references to those identifiers are a compile error under LL's compiler. Need to either error on identifiers over 255 bytes or allow them to be declared and shadows but don't allow later references.

SaladDais commented 2 years ago

Closing for same reason as #11