Skip to content

Fix out of bounds crash of truncated token replacement#75

Open
Econa77 wants to merge 1 commit into
instacart:masterfrom
Econa77:feature/fix-out-of-bounds
Open

Fix out of bounds crash of truncated token replacement#75
Econa77 wants to merge 1 commit into
instacart:masterfrom
Econa77:feature/fix-out-of-bounds

Conversation

@Econa77
Copy link
Copy Markdown

@Econa77 Econa77 commented Apr 2, 2021

No description provided.

// the first line we replace, we'll truncate it, after that, we 100% replace lines of the original string with truncation lines
for (index, tokenLine) in tokenLines.enumerated() {
let originalIndex = self.numberOfLines - tokenLines.count + index
let originalIndex = lines.count - tokenLines.count + index
Copy link
Copy Markdown
Author

@Econa77 Econa77 Apr 2, 2021

Choose a reason for hiding this comment

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

The settings when the app crashed were as follows.

  • self.numberOfLines: 5
  • lines.count: 4
  • tokenLines.count: 2

As a result, the originalIndex was out of range of lines and crashed at times other than the first replacement.
When there are many lines with only line breaks, the number of lines in lines may not match with numberOfLines, so the index is acquired from the number of lines in lines.

@Econa77
Copy link
Copy Markdown
Author

Econa77 commented Apr 2, 2021

The snapshot test is failing, but when I try it, it seems to fail the same before the change.

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.

1 participant