Fixed a index out of bound error when trying to delete the first line… #1003
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix a index out of bound error when deleting the first line of a document. (Issue #1004, which was introduced by #676) The error comes from a case where pos is 0 and we are trying to access character at pos - 1, which is -1 but then overflows to MAX_UINT64 / MAX_UINT32 because pos is of type NSUInteger.
Notes to reviewers:
This is just a temporary fix to silent the error. However, the nature of the issue extend beyond the index out of bound error. The code is comparing pos against index, which makes no sense to me. pos is a position in terms of characters but index is line the line number. It definitely feels wrong to compare them, but I was not able to figure out what the expected behavior is with my time constraints. So I'm going to leave that to those who are more familiar with the code. Filed #1005.