From 61a2681597373845a419e1f97b21b1dc383460ec Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 18 Jan 2010 21:47:45 +0000 Subject: [PATCH] [BUG_FIXED] Fix loading encoding file making file corrupted (after saving). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@598 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/ScitillaComponent/Buffer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index d02733d3b..61668e358 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -640,7 +640,7 @@ BufferID FileManager::bufferFromDocument(Document doc, bool dontIncrease, bool d bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Read * UnicodeConvertor, LangType language, int & encoding, formatType *pFormat) { const int blockSize = 128 * 1024; //128 kB - char data[blockSize+1]; + char data[blockSize+8]; FILE *fp = generic_fopen(filename, TEXT("rb")); if (!fp) return false; @@ -687,11 +687,13 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, Utf8_16_Rea do { lenFile = fread(data, 1, blockSize, fp); - if (isFirstTime) + // check if file contain any BOM + if (isFirstTime) { if (Utf8_16_Read::determineEncoding((unsigned char *)data, lenFile) != uni8Bit) { - //printStr(TEXT("hola")); + // if file contains any BOM, then encoding will be erased, + // and the document will be interpreted as UTF encoding = -1; } isFirstTime = false;