[EU-FOSSA] Fix crash issue by command "On Selection->Open File"

Fix crash issue by command "On Selection->Open File" while the number of selected characters is exeed 2048.
This commit is contained in:
Don HO 2019-03-22 13:57:28 +01:00
parent f7d92eb992
commit 63d3a42c64
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

View File

@ -2252,11 +2252,17 @@ generic_string ScintillaEditView::getLine(size_t lineNumber)
void ScintillaEditView::getLine(size_t lineNumber, TCHAR * line, int lineBufferLen) void ScintillaEditView::getLine(size_t lineNumber, TCHAR * line, int lineBufferLen)
{ {
// make sure the buffer length is enough to get the whole line
auto lineLen = execute(SCI_LINELENGTH, lineNumber);
if (lineLen >= lineBufferLen)
return;
WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance(); WcharMbcsConvertor *wmc = WcharMbcsConvertor::getInstance();
UINT cp = static_cast<UINT>(execute(SCI_GETCODEPAGE)); UINT cp = static_cast<UINT>(execute(SCI_GETCODEPAGE));
char *lineA = new char[lineBufferLen]; char *lineA = new char[lineBufferLen];
// From Scintilla documentation for SCI_GETLINE: "The buffer is not terminated by a 0 character." // From Scintilla documentation for SCI_GETLINE: "The buffer is not terminated by a 0 character."
memset(lineA, 0x0, sizeof(char) * lineBufferLen); memset(lineA, 0x0, sizeof(char) * lineBufferLen);
execute(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineA)); execute(SCI_GETLINE, lineNumber, reinterpret_cast<LPARAM>(lineA));
const TCHAR *lineW = wmc->char2wchar(lineA, cp); const TCHAR *lineW = wmc->char2wchar(lineA, cp);
lstrcpyn(line, lineW, lineBufferLen); lstrcpyn(line, lineW, lineBufferLen);