From 2fd963d9325e24d9c804be1ba17d5c368267a5dc Mon Sep 17 00:00:00 2001 From: dail8859 Date: Sun, 25 Oct 2015 22:34:25 -0400 Subject: [PATCH] Fix wrong EOL mode for big files Closes #1054, Fixes #1002 The problem is if fread() is called multiple times, then UnicodeConvertor->convert() is called multiple times, which causes m_pNewBuf to point to the last read in chunk. Then after the entire file was loaded, getEOLFormatForm(UnicodeConvertor.getNewBuf(), ...) was being used which was only trying to detect the EOL mode from the last read in chunk. If this last chunk started with \n then the file was detected as Unix line endings. The file linked from issue #1002 happened to have just the right situation where this occurred. --- PowerEditor/src/ScitillaComponent/Buffer.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 00bd410ec..a371ae48c 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -627,15 +627,6 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin if (encoding == -1) { - // 3 formats : WIN_FORMAT, UNIX_FORMAT and MAC_FORMAT - if (nullptr != UnicodeConvertor.getNewBuf()) - { - FormatType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(),ndds._format); - buf->setFormat(format); - } - else - buf->setFormat(ndds._format); - UniMode um = UnicodeConvertor.getEncoding(); if (um == uni7Bit) um = (ndds._openAnsiAsUtf8) ? uniCookie : uni8Bit; @@ -647,9 +638,10 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin // Test if encoding is set to UTF8 w/o BOM (usually for utf8 indicator of xml or html) buf->setEncoding((encoding == SC_CP_UTF8)?-1:encoding); buf->setUnicodeMode(uniCookie); - buf->setFormat(bkformat); } + buf->setFormat(bkformat); + //determine buffer properties ++_nextBufferID; return id; @@ -1467,6 +1459,8 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char { lenConvert = UnicodeConvertor->convert(data, lenFile); _pscratchTilla->execute(SCI_APPENDTEXT, lenConvert, (LPARAM)(UnicodeConvertor->getNewBuf())); + if (format == FormatType::unknown) + format = getEOLFormatForm(UnicodeConvertor->getNewBuf(), UnicodeConvertor->getNewSize(), FormatType::unknown); } if (_pscratchTilla->execute(SCI_GETSTATUS) != SC_STATUS_OK)