diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 1e206a9b5..c21646fcd 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1917,7 +1917,7 @@ void ScintillaEditView::showCallTip(int startPos, const TCHAR * def) generic_string ScintillaEditView::getLine(int lineNumber) { int lineLen = execute(SCI_LINELENGTH, lineNumber); - const int bufSize = lineLen; + const int bufSize = lineLen + 1; std::unique_ptr buf = std::make_unique(bufSize); getLine(lineNumber, buf.get(), bufSize); return buf.get(); @@ -1928,6 +1928,8 @@ void ScintillaEditView::getLine(int lineNumber, TCHAR * line, int lineBufferLen) WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); unsigned int cp = execute(SCI_GETCODEPAGE); char *lineA = new char[lineBufferLen]; + // From Scintilla documentation for SCI_GETLINE: "The buffer is not terminated by a 0 character." + memset(lineA, '\0', sizeof(char) * lineBufferLen); execute(SCI_GETLINE, lineNumber, (LPARAM)lineA); const TCHAR *lineW = wmc->char2wchar(lineA, cp); lstrcpyn(line, lineW, lineBufferLen);