Crash when indenting short lines (pressing tab key)
What steps will reproduce the problem?
- Compare two empty files
- Enter two lines with text "a" and "b" in the right panel
- Select both lines
- Press tab
What is the expected output? What do you see instead?
Expect indenting to happen, like when happens if the selected text is already indented. Instead, crashes and sends error report.
What version of TortoiseGit and Git are you using? On what operating system?
220.127.116.11 and latest master.
Please provide any additional information below.
So I built and debugged the code. The crash happens in CBaseView::GetIndentCharsForLine in the (m_nTabMode & TABMODE_SMARTINDENT) part because GetViewLine(i) does not take kindly to a negative index.
I'd like to fix it but I'm mystified about the code:
line.GetLength() > m_nTabSize: if it counted the number of leading spaces, I would understand. But just length, how is that a hint that spaces are wanted? Anyway, the fact that lines usually are longer is the reason indentation usually doesn't crash.
bool above = i > 0... and not
>= 0while clearly y = 0 and GetViewLine(y) returns the first line. So if there's a tab on the line above, we want to insert tabs, but not if that line is the first line??
nTabMode = 1(meaning spaces) if both the nth line above and nth line below are longer than tab size. Even if I understood that rule, why not if the 1st line above is longer, the 1st line below is not, but the 2nd line below is longer?