Skip to content

Commit

Permalink
Prevent convert line endings for large file.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Dec 8, 2024
1 parent 9082a2e commit 850b8c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
21 changes: 12 additions & 9 deletions src/Edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(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<size_t>(INT_MAX)) {
return;
}
}
#else
const DWORD dwLength = static_cast<DWORD>(SciCall_GetLength()) + static_cast<DWORD>(SciCall_GetLineCount());
if (dwLength >= INT_MAX) {
return;
}
#endif
}

SciCall_ConvertEOLs(iEOLMode);
Expand Down
4 changes: 2 additions & 2 deletions src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/SciCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ inline void SciCall_EndUndoAction() noexcept {
SciCall(SCI_ENDUNDOACTION, 0, 0);
}

inline int SciCall_GetUndoActions() noexcept {
return static_cast<int>(SciCall(SCI_GETUNDOACTIONS, 0, 0));
inline size_t SciCall_GetUndoActions() noexcept {
return SciCall(SCI_GETUNDOACTIONS, 0, 0);
}

inline void SciCall_SetChangeHistory(int changeHistory) noexcept {
Expand Down

0 comments on commit 850b8c5

Please sign in to comment.