Skip to content

Invalid code generation when function has public specifier only in its declaration #621

@Daniel-Cortez

Description

@Daniel-Cortez

Issue description:

#include <a_samp>

public Func();
Func()
{
	printf("Func()");
}

main()
{
	printf("main()");
	CallLocalFunction("Func", "");
}

This code makes function main() call itself recursively, causing a stack/heap collision.
The reason is that Func() is defined without the public specifier and the function is not called directly, so the compiler doesn't generate any code for it, thinking it's unused. But because Func() has a public specifier in its declaration, the compiler still creates an entry for this function in the public functions table.
As a result, since there's no code for Func(), the entry points at main() instead, which causes recursion.

Minimal complete verifiable example (MCVE):

See above.

Workspace Information:

  • Compiler version: 3.2.3664, 3.10.10
  • Command line arguments provided (or sampctl version):
  • Operating System:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions