Crash when indenting short lines in TortoiseMerge (pressing tab key)

25 views
Skip to first unread message

Stein Somers

unread,
Nov 5, 2019, 5:20:18 PM11/5/19
to TortoiseSVN
To reproduce: compare 2 empty files. In Settings, make sure "Smart tab char" in on. On the right, insert 1 line with 1 character and a newline. Select the line. Press tab (and seek cover).

I filed this under TortoiseGit but noticed the code was copied from TortoiseSVN. Digging further, the bug comes from a single changeset 25713 by one Stefan K, specifically to "improve auto-detection of tab-mode" which replaced the safe code above ? GetViewLine(i)[0] : '\0' with the one crashing now.

Apart from the bug I have some remarks about the CBaseView::GetIndentCharsForLine code here:
  • if (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 nTabMode is set and the crashing code is skipped.
  • bool above = i > 0... and not >= 0 while in this example y = 0 and GetViewLine(y) indeed 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?
  • if (m_nTabMode & TABMODE_SMARTINDENT): why twice? Probably the good intent was to move the nTabMode == -1 test out of the for loop to this more visible place (hence the not-yet-useful break statements inside the loop).
Stein

Stefan

unread,
Nov 7, 2019, 10:49:04 AM11/7/19
to TortoiseSVN
I'll take a look soon.

Stefan

unread,
Nov 7, 2019, 2:20:23 PM11/7/19
to TortoiseSVN
crash fixed in r28690, and the space/tab detection improved in r28691
Reply all
Reply to author
Forward
0 new messages