Skip to content

Return nil on applying() failure instead of crashing #26575

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

Merged
merged 3 commits into from
Aug 10, 2019

Conversation

numist
Copy link
Member

@numist numist commented Aug 8, 2019

The application of a diff onto an invalid base state is supposed to cause nil to be returned from applying(), but instead it just crashes with an index out of bounds error.

Oops.

Generally speaking maintaining consistent diff and base states is the programmer's responsibility, but not crashing on invalid application is necessary for diffs to be useful as a boundary type for passing between modules so someone else's bug doesn't turn into anyone else's crash.

This PR includes exhaustive coverage of the boundary between application success and failure as well as fixes for the failing tests, including the test from the original report.

Resolves <rdar://problem/53663769>

@numist numist requested a review from lorentey August 8, 2019 23:55
@numist
Copy link
Member Author

numist commented Aug 8, 2019

@swift-ci Please test

target.append(contentsOf: source[start..<index])
}

difference._fastEnumeratedApply { change in
Copy link
Member Author

Choose a reason for hiding this comment

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

This hunk is all whitespace changes with the exception of the addition of a do { … } catch { … } block and associated sprinklings of try.

let start = index
source.formIndex(&index, offsetBy: count)
if !source.formIndex(&index, offsetBy: count, limitedBy: source.endIndex) {
throw _ApplicationError.failed
Copy link
Member

Choose a reason for hiding this comment

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

These throws may throw off people who break on all throws. We can fix this later if it proves annoying.

@lorentey
Copy link
Member

lorentey commented Aug 9, 2019

@swift-ci test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@numist
Copy link
Member Author

numist commented Aug 10, 2019

@swift-ci test

@swift-ci

This comment has been minimized.

@swift-ci

This comment has been minimized.

@numist numist merged commit 9f90fb1 into swiftlang:master Aug 10, 2019
@numist numist deleted the numist/application-denied branch August 10, 2019 18:37
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.

4 participants