diff --git a/src/Edit.cpp b/src/Edit.cpp index 2fb3c296d8..4de6ef92b3 100644 --- a/src/Edit.cpp +++ b/src/Edit.cpp @@ -4365,22 +4365,25 @@ void EditEnsureSelectionVisible() noexcept { } void EditEnsureConsistentLineEndings() noexcept { + const size_t lineCount = SciCall_GetLineCount(); + const size_t actions = SciCall_GetUndoActions(); + if (lineCount + actions >= static_cast(INT_MAX)) { + // Scintilla undo stack is indexed with int + return; + } + const int iEOLMode = SciCall_GetEOLMode(); if (iEOLMode == SC_EOL_CRLF) { #if defined(_WIN64) const int options = SciCall_GetDocumentOptions(); - if (!(options & SC_DOCUMENTOPTION_TEXT_LARGE)) { - const Sci_Position dwLength = SciCall_GetLength() + SciCall_GetLineCount(); - if (dwLength >= INT_MAX) { + if (!(options & SC_DOCUMENTOPTION_TEXT_LARGE)) +#endif + { + const size_t dwLength = SciCall_GetLength() + lineCount; + if (dwLength >= static_cast(INT_MAX)) { return; } } -#else - const DWORD dwLength = static_cast(SciCall_GetLength()) + static_cast(SciCall_GetLineCount()); - if (dwLength >= INT_MAX) { - return; - } -#endif } SciCall_ConvertEOLs(iEOLMode); diff --git a/src/Notepad4.cpp b/src/Notepad4.cpp index 1da7ca079a..c16677300f 100644 --- a/src/Notepad4.cpp +++ b/src/Notepad4.cpp @@ -5063,8 +5063,8 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) { case StatusItem_EolMode: { constexpr UINT mask = (SC_EOL_LF << 2*SC_EOL_CRLF) | (SC_EOL_CR << 2*SC_EOL_LF) | (SC_EOL_CRLF << 2*SC_EOL_CR); - iCurrentEOLMode = (mask >> (iCurrentEOLMode << 1)) & 3; - ConvertLineEndings(iCurrentEOLMode); + const int iNewEOLMode = (mask >> (iCurrentEOLMode << 1)) & 3; + ConvertLineEndings(iNewEOLMode); return TRUE; } diff --git a/src/SciCall.h b/src/SciCall.h index 011ebba18b..9e0ae22af8 100644 --- a/src/SciCall.h +++ b/src/SciCall.h @@ -260,8 +260,8 @@ inline void SciCall_EndUndoAction() noexcept { SciCall(SCI_ENDUNDOACTION, 0, 0); } -inline int SciCall_GetUndoActions() noexcept { - return static_cast(SciCall(SCI_GETUNDOACTIONS, 0, 0)); +inline size_t SciCall_GetUndoActions() noexcept { + return SciCall(SCI_GETUNDOACTIONS, 0, 0); } inline void SciCall_SetChangeHistory(int changeHistory) noexcept {