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

Fix use of errno in SystemError #455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Bo98
Copy link

@Bo98 Bo98 commented Dec 24, 2023

Calling errno inside SystemError.description() is far too late and will almost always return the wrong error number. Instead, pass the errno at the throw site, which is consistent with how most of the other SystemError throws work.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

This seems like the right thing to do. Should double check that there's no other instance that needs to be updated for close.

@compnerd
Copy link
Member

@swift-ci please test

@MaxDesiatov MaxDesiatov added the bug label Jan 2, 2024
Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

I wonder if there's a test case one could come up with to reproduce the original issue, verify that the change fixes it, and prevent future regressions?

@MaxDesiatov MaxDesiatov self-requested a review January 2, 2024 11:07
@neonichu
Copy link
Contributor

neonichu commented Jan 2, 2024

I think we should continue to check for a return value of -1 before we consult errno.

@Bo98
Copy link
Author

Bo98 commented Jan 2, 2024

I think we should continue to check for a return value of -1 before we consult errno.

Only return values of 0 and -1 are defined in POSIX. So what value we should be using instead for a theoretical -2 is unclear to me.

RETURN VALUES
     Upon successful completion, a value of 0 is returned.  Otherwise, a value
     of -1 is returned and the global integer variable errno is set to
     indicate the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants