pawn-lang / compiler

Pawn compiler for SA-MP with bug fixes and new features - runs on Windows, Linux, macOS
Other
301 stars 71 forks source link

`sizeof` default arg with offsets #692

Open Y-Less opened 2 years ago

Y-Less commented 2 years ago

Issue description:

sizeof when used as a default argument to get the size of an array should always return a size of an array, never the size of a cell. You can pass offsets in to arrays with arr[n] and the compiler correctly compiles that as passing an array offset to index n, but the sizeof seems to do sizeof (arr[n]) instead of sizeof (arr) - n. This is counter-intuitive as the sizeof is applied to the destination parameter, which is declared as an array, not the passed data, which could be anything.

Minimal complete verifiable example (MCVE):

Func(str[], len = sizeof (str))
{
    printf("%s %d", str, len);
}

main()
{
    new str[] = "Hello World";
    Func(str);
    Func(str[6]);
}

This prints:

Hello World 12
World 1

I'd expect:

Hello World 12
World 6

Or at the very least:

Hello World 12
World 12

But that can lead to OOBs.

Workspace Information:

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity.