-
Notifications
You must be signed in to change notification settings - Fork 124
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 close error message #433
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,8 +347,14 @@ extension SystemError: CustomStringConvertible { | |
switch self { | ||
case .chdir(let errno, let path): | ||
return "chdir error: \(strerror(errno)): \(path)" | ||
case .close(let errno): | ||
return "close error: \(strerror(errno))" | ||
case .close(let err): | ||
let errorMessage: String | ||
if err == -1 { // if the return code is -1, we need to consult the global `errno` | ||
errorMessage = strerror(errno) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need to copy this string immediately or else it's UB and you might get garbage or worse: man strerror:
So you want to save a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we are basically doing that, the |
||
} else { | ||
errorMessage = strerror(err) | ||
} | ||
return "close error: \(errorMessage)" | ||
case .exec(let errno, let path, let args): | ||
let joinedArgs = args.joined(separator: " ") | ||
return "exec error: \(strerror(errno)): \(path) \(joinedArgs)" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
errno
is only guaranteed to overridden when the syscall fails, i.e. returns-1
.