Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

src/: Prefer return over exit in main function #1201

Closed
wants to merge 1 commit into from

Conversation

stoeckmann
Copy link
Contributor

@stoeckmann stoeckmann commented Feb 3, 2025

Argued with myself about creating this PR or not, so here are my pro and contra arguments:

return over exit

  • Allows the stack protector of main function to work

exit over return

  • Prevents copy&paste errors if code is moved from main into another function
  • Counter argument to stack protector: Writing far enough behind the end of stack could modify the stack protector behavior itself
  • If no stack protector is compiled in, this change actually enables stack attacks in main function

Either/or

  • Unifies the code base a bit more

Keep as is

  • Every change has potential of failure
  • Counter argument to stack protector: Pretty much every error handling with exit in a function circumvents the protector

Since I created the PR, I see benefits in allowing the stack protector to work and unification process is always nice.

But let's not rush this. Small benefit anyway.

Calling exit directly circumvents the stack protector of the main
function. Assist the runtime in potentially detecting flaws without
adjusting the code base too much.

Signed-off-by: Tobias Stoeckmann <[email protected]>
Comment on lines 47 to +50
if (check_uids) {
if (have_sub_uids(owner, start, count))
exit(0);
exit(1);
return 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For error handling, I very much prefer exit(3).

For successful exiting, I still have some preference for exit(3), but could be convinced of using return.
I think exit(3) has more readability, as it tells that the program is over, while with return you have to remember (and check) that you're in main().

BTW, right here there's a successful exit(3) call unchanged. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can close this PR. I'm not fully convinced but wanted to offer in case someone really wants this. So ... No. :)

@stoeckmann stoeckmann closed this Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants