OSDN Git Service

[ 1900733 ] WM detects invalid UTF-8 sequence as UTF-8
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 24 Feb 2008 12:29:10 +0000 (12:29 +0000)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 24 Feb 2008 12:29:10 +0000 (12:29 +0000)
Docs/Users/ChangeLog.txt
Src/Common/Utf8FileDetect.cpp

index b655889..4f8e5b9 100644 (file)
@@ -6,6 +6,7 @@ WinMerge 2.7.7.6
   Remove sintance.h/sintance.cpp as not compatible with GPL (#1886580)
   BugFix: Ignore codepage specified on File Encoding dialog if file was 
     detected as UTF-8 (#1900728)
+  BugFix: Recognize invalid UTF-8 sequence as UTF-8 (#1900733)
 
 WinMerge 2.7.7.5 - 2008-02-22 (r5069)
   Cleaning up Help-menu (#1875111)
index 9fe9d1d..7b3e4c9 100644 (file)
@@ -50,7 +50,9 @@ bool CheckForInvalidUtf8(LPBYTE pBuffer, int size)
        bool bUTF8 = false;
        for (int i = 0; i < (size - 3); ++i)
        {
-               if ((*pVal2 & 0xE0) == 0xC0)
+               if ((*pVal2 & 0x80) == 0x00)
+                       ;
+               else if ((*pVal2 & 0xE0) == 0xC0)
                {
                        pVal2++;
                        i++;
@@ -58,7 +60,7 @@ bool CheckForInvalidUtf8(LPBYTE pBuffer, int size)
                                return true;
                        bUTF8 = true;
                }
-               if ((*pVal2 & 0xF0) == 0xE0)
+               else if ((*pVal2 & 0xF0) == 0xE0)
                {
                        pVal2++;
                        i++;
@@ -70,7 +72,7 @@ bool CheckForInvalidUtf8(LPBYTE pBuffer, int size)
                                return true;
                        bUTF8 = true;
                }
-               if ((*pVal2 & 0xF8) == 0xF0)
+               else if ((*pVal2 & 0xF8) == 0xF0)
                {
                        pVal2++;
                        i++;
@@ -86,6 +88,8 @@ bool CheckForInvalidUtf8(LPBYTE pBuffer, int size)
                                return true;
                        bUTF8 = true;
                }
+               else
+                       return true;
                pVal2++;
        }
        if (bUTF8)