From 86c2e2973edf90b1b2f24b6d512b5dfd0dce6317 Mon Sep 17 00:00:00 2001 From: Ianos Gnatiuc Date: Mon, 5 Jun 2006 19:03:19 +0000 Subject: [PATCH] Golded+ can crash in editor if line is 0 char long. --- golded3/geedit.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/golded3/geedit.cpp b/golded3/geedit.cpp index e2370e8..2b8163a 100644 --- a/golded3/geedit.cpp +++ b/golded3/geedit.cpp @@ -725,14 +725,16 @@ int IEclass::downoneline(uint __row) { // ------------------------------------------------------------------ -void IEclass::GoEOL() { - +void IEclass::GoEOL() +{ GFTRK("EditGoEOL"); // Move cursor to the last char on the line - col = currline->txt.length(); - if((currline->txt[col-1] == '\n') or ((col != mincol) and (currline->txt[col-1] == ' '))) - --col; + if (mincol != (col = currline->txt.length())) + { + if ((currline->txt[col-1] == '\n') || (currline->txt[col-1] == ' ')) + --col; + } // String must not be longer than the window width _test_haltab(col > maxcol, col, maxcol); @@ -1276,14 +1278,20 @@ void IEclass::insertchar(char __ch) { // ------------------------------------------------------------------ -void IEclass::DelChar() { - +void IEclass::DelChar() +{ GFTRK("EditDelChar"); Line* _thisline = currline; Line* _nextline = currline->next; uint _thislen = _thisline->txt.length(); + if (!_nextline && (col == _thislen - 1) && (_thisline->txt[col] == '\n')) + { + GFTRK(0); + return; + } + // Cannot delete at or beyond the nul-terminator if(col < _thislen) { Undo->PushItem(EDIT_UNDO_DEL_CHAR|batch_mode);