Skip to content

Fix use of errno in SystemError#455

Open
Bo98 wants to merge 1 commit into
swiftlang:mainfrom
Bo98:close-errno-fix
Open

Fix use of errno in SystemError#455
Bo98 wants to merge 1 commit into
swiftlang:mainfrom
Bo98:close-errno-fix

Conversation

@Bo98

@Bo98 Bo98 commented Dec 24, 2023

Copy link
Copy Markdown

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.

@compnerd compnerd left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

@swift-ci please test

@MaxDesiatov MaxDesiatov added the bug label Jan 2, 2024

@MaxDesiatov MaxDesiatov left a comment

Copy link
Copy Markdown
Contributor

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

neonichu commented Jan 2, 2024

Copy link
Copy Markdown
Contributor

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

@Bo98

Bo98 commented Jan 2, 2024

Copy link
Copy Markdown
Author

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.

@jakepetroules

Copy link
Copy Markdown
Contributor

@swift-ci test

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.

5 participants