Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
Daniel-Cortez opened this issue Dec 16, 2020 · 2 comments

Comments

@Daniel-Cortez
Copy link
Contributor

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:
@Daniel-Cortez
Copy link
Contributor Author

Daniel-Cortez commented Dec 16, 2020

For now I'm not sure how to properly handle this bug.
Should we silently treat such functions as public, even if they don't have the public specifier in their definition, or rather issue error 025 (function heading differs from prototype)?
@Y-Less?

@stale
Copy link

stale bot commented Jun 22, 2021

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

@stale stale bot added the state: stale label Jun 22, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant