Skip to content

Commit

Permalink
Fixed: Widen TerminalRow's index so very long lines don't overflow it.
Browse files Browse the repository at this point in the history
This prevents the crash in termux#3839, but not by enough to call it done.
Termux gets stuck on the very bad line and is responsive, but laggy
enough to trigger ANRs. It's possible to ^C in this state and get your
terminal back with no apparent damage.
  • Loading branch information
tstein committed Feb 16, 2024
1 parent 8e3a898 commit 14dde76
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public final class TerminalRow {
private final int mColumns;
/** The text filling this terminal row. */
public char[] mText;
/** The number of java char:s used in {@link #mText}. */
private short mSpaceUsed;
/** The number of java chars used in {@link #mText}. */
private int mSpaceUsed;
/** If this row has been line wrapped due to text output at the end of line. */
boolean mLineWrap;
/** The style bits of each cell in the row. See {@link TextStyle}. */
Expand Down Expand Up @@ -118,7 +118,7 @@ private boolean wideDisplayCharacterStartingAt(int column) {
public void clear(long style) {
Arrays.fill(mText, ' ');
Arrays.fill(mStyle, style);
mSpaceUsed = (short) mColumns;
mSpaceUsed = mColumns;
mHasNonOneWidthOrSurrogateChars = false;
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public void setChar(int columnToSet, int codePoint, long style) {
throw new IllegalArgumentException("Cannot put wide character in last column");
} else if (columnToSet == mColumns - 2) {
// Truncate the line to the second part of this wide char:
mSpaceUsed = (short) newNextColumnIndex;
mSpaceUsed = newNextColumnIndex;
} else {
// Overwrite the contents of the next column, which mean we actually remove java characters. Due to the
// check at the beginning of this method we know that we are not overwriting a wide char.
Expand Down

0 comments on commit 14dde76

Please sign in to comment.