From f3934fadb726ae4471e1a8008da066bf3ebcfa1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20J=C3=B6nsson?= Date: Mon, 1 Jun 2015 18:55:25 +0200 Subject: [PATCH] Fix array termination error. --- PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 1e206a9b..c21646fc 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);