View Issue Details

IDProjectCategoryView StatusLast Update
0002686Far ManagerEditorpublic2014-06-04 18:13
Reporter4eyes Assigned ToDrKnS  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.0 
Fixed in Version3.0 
Summary0002686: Debug build crashes in editor (fix included)
DescriptionHello,

I got stuck over two issues with debug build a month ago, while developing new plugin, and it looks unfixed up to Today's head on SVN (rev. 11833). Clean build and configuration, nothing additional installed.

Issues are not critical and not reproduced on release build, however, it's annoying on debug one and may be fixed in a minimal efforts.

1. Trying to compare uncomparable iterators on editor start, leads to assertion fairure on MSVC 2012 v.11.0.61030 Update 4 on Win 7 x64, Win32 debug build.

2. Attempt to decrement Line.begin() iterator: is performed on SHIFT-LEFT or SHIFT-CTRL-LEFT keys, cursor is located not at line start on a first line.
Steps To Reproduce1. Perform debug build. Tested on revisions up to
2. Execute in console: echo "Hello world" > test.txt
3. Open "test.txt" in editor - it crashes with a message like

Debug Assertion Failed!
Program: E:\Tools\farmanager\unicode_far\Debug.32.vc\Far.exe
File: C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\list
Line: 289
Expression: list iterators incompatible

When I managed to open editor on test.txt:
4. Press RIGHT key twice
5a. Press SHIFT-LEFT
5b. Press CTRL-SHIFT-LEFT

Both 3, 5a and 5b leads to crash.
Additional InformationBug cause and fix is trivial. Patch for revision 11833 is attached to this bug.

A) Cause of issue when loading file into editor:
  1. Editor::Editor() call => Editor::InsertString() - insert empty line and point
     BlockStart, VBlockStart to that line.
  2. FileEditor::LoadFile() call => Editor::FreeAllocatedData() => Lines.clear() - this invalidates old Line iterators, e.g. BlockStart, VBlockStart
  3. Forgot to update BlockStart, VBlockStart
  4. Editor::ShowEditor() => Editor::FastShow() => ... => Editor::EditorControl(ECTL_GETINFO, ...) - trying to compare invalidated iterators BlockStart, VBlockStart with Lines.end() leads to unexpected behaviour and assertion failure inside CRT.

B) [CTRL-]SHIIFT-LEFT: it's just undefined behaviour to call std::prev on list begin even when Editor's caret position by X-axis is not zero :)

Please review my patch and feel free to ask additional questions, if needed.
TagsNo tags attached.
Build3915

Activities

4eyes

2014-05-24 00:25

reporter  

unicode_far.r11833.patch (945 bytes)   
Index: editor.cpp
===================================================================
--- editor.cpp	(revision 11834)
+++ editor.cpp	(working copy)
@@ -178,11 +178,11 @@
 void Editor::FreeAllocatedData(bool FreeUndo)
 {
 	Lines.clear();
+	BlockStart = VBlockStart = LastGetLine = FirstLine = LastLine = CurLine = Lines.end(); // don't forget to re-create invalidated iterators after clear
 	UndoData.clear();
 	UndoSavePos = UndoPos = UndoData.end();
 	UndoSkipLevel=0;
 	ClearSessionBookmarks();
-	FirstLine = LastLine = CurLine = Lines.end();
 	NumLastLine = 0;
 }
 
@@ -1196,9 +1196,9 @@
 			if (!CurPos && CurLine == FirstLine)
 				return TRUE;
 
-			auto PrevLine = std::prev(CurLine);
 			if (!CurPos) //������ � ����� ������
 			{
+				auto PrevLine = std::prev(CurLine); // iterator may be non-decrementable on first line
 				if (SelAtBeginning) //������ � ����� �����
 				{
 					BlockStart = PrevLine;
unicode_far.r11833.patch (945 bytes)   

DrKnS

2014-05-24 08:05

administrator   bugnote:0012430

3915

Issue History

Date Modified Username Field Change
2014-05-24 00:25 4eyes New Issue
2014-05-24 00:25 4eyes File Added: unicode_far.r11833.patch
2014-05-24 08:04 DrKnS Assigned To => DrKnS
2014-05-24 08:04 DrKnS Status new => assigned
2014-05-24 08:05 DrKnS Note Added: 0012430
2014-05-24 08:05 DrKnS Status assigned => feedback
2014-06-04 18:13 DrKnS Build => 3915
2014-06-04 18:13 DrKnS Status feedback => closed
2014-06-04 18:13 DrKnS Resolution open => fixed
2014-06-04 18:13 DrKnS Fixed in Version => 3.0