Skip to content
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 out of bounds crash of truncated token replacement #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Classes/Drawing/Truncation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension NantesLabel {
// Walk across all the lines of truncation, replacing lines starting with our last line - the number of truncation token lines we have
// 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
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.


// We want to replace every other line besides the first truncated line completely with the lines from the truncation token
guard index == 0 else {
Expand Down