scintilla: Fix invalid memory access in MoveSelectedLines

Fixes #2066.

X-Scintilla-Commit-ID: df5c32512d3d6b71ee6138c709b392258c3a1991,
                       25a0367e9349c8475c619a054af7bf1daf15b04c
X-Scintilla-Bug-ID: https://sourceforge.net/p/scintilla/bugs/2078/
This commit is contained in:
Colomban Wendling 2019-04-27 16:12:50 +02:00
parent 44c26adbc3
commit d551765d59

View File

@ -1003,6 +1003,10 @@ void Editor::VerticalCentreCaret() {
void Editor::MoveSelectedLines(int lineDelta) { void Editor::MoveSelectedLines(int lineDelta) {
if (sel.IsRectangular()) {
return;
}
// if selection doesn't start at the beginning of the line, set the new start // if selection doesn't start at the beginning of the line, set the new start
Sci::Position selectionStart = SelectionStart().Position(); Sci::Position selectionStart = SelectionStart().Position();
const Sci::Line startLine = pdoc->SciLineFromPosition(selectionStart); const Sci::Line startLine = pdoc->SciLineFromPosition(selectionStart);
@ -1042,7 +1046,6 @@ void Editor::MoveSelectedLines(int lineDelta) {
SelectionText selectedText; SelectionText selectedText;
CopySelectionRange(&selectedText); CopySelectionRange(&selectedText);
Sci::Position selectionLength = SelectionRange(selectionStart, selectionEnd).Length();
const Point currentLocation = LocationFromPosition(CurrentPosition()); const Point currentLocation = LocationFromPosition(CurrentPosition());
const Sci::Line currentLine = LineFromLocation(currentLocation); const Sci::Line currentLine = LineFromLocation(currentLocation);
@ -1055,7 +1058,7 @@ void Editor::MoveSelectedLines(int lineDelta) {
pdoc->InsertString(pdoc->Length(), eol, strlen(eol)); pdoc->InsertString(pdoc->Length(), eol, strlen(eol));
GoToLine(currentLine + lineDelta); GoToLine(currentLine + lineDelta);
selectionLength = pdoc->InsertString(CurrentPosition(), selectedText.Data(), selectionLength); Sci::Position selectionLength = pdoc->InsertString(CurrentPosition(), selectedText.Data(), selectedText.Length());
if (appendEol) { if (appendEol) {
const Sci::Position lengthInserted = pdoc->InsertString(CurrentPosition() + selectionLength, eol, strlen(eol)); const Sci::Position lengthInserted = pdoc->InsertString(CurrentPosition() + selectionLength, eol, strlen(eol));
selectionLength += lengthInserted; selectionLength += lengthInserted;