OSDN Git Service

Merge with stable
[winmerge-jp/winmerge-jp.git] / Src / Common / unicoder.cpp
index 58df74c..a58a9d6 100644 (file)
@@ -31,7 +31,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
 #endif
 
 using Poco::UnicodeConverter;
-using Poco::UInt64;
+using boost::uint64_t;
 
 namespace ucr
 {
@@ -1157,10 +1157,10 @@ std::string toThreadCP(const std::wstring& str)
  * @param [in] size Size of the buffer in bytes.
  * @return true if invalid bytes found, false otherwise.
  */
-bool CheckForInvalidUtf8(const char *pBuffer, int size)
+bool CheckForInvalidUtf8(const char *pBuffer, size_t size)
 {
        unsigned char * pVal2 = (unsigned char *)pBuffer;
-       for (int j = 0; j < size; ++j)
+       for (size_t j = 0; j < size; ++j)
        {
                if ((*pVal2 == 0xC0) || (*pVal2 == 0xC1) || (*pVal2 >= 0xF5))
                        return true;
@@ -1168,7 +1168,9 @@ bool CheckForInvalidUtf8(const char *pBuffer, int size)
        }
        pVal2 = (unsigned char *)pBuffer;
        bool bUTF8 = false;
-       for (int i = 0; i < (size - 3); ++i)
+       if (size < 3)
+               return false;
+       for (size_t i = 0; i < (size - 3); ++i)
        {
                if ((*pVal2 & 0x80) == 0x00)
                        ;
@@ -1229,7 +1231,7 @@ bool CheckForInvalidUtf8(const char *pBuffer, int size)
  * FF FE 00 00 UTF-32, little endian
  * 00 00 FE FF UTF-32, big-endian
  */
-UNICODESET DetermineEncoding(const unsigned char *pBuffer, UInt64 size, bool * pBom)
+UNICODESET DetermineEncoding(const unsigned char *pBuffer, uint64_t size, bool * pBom)
 {
        UNICODESET unicoding = NONE;
        *pBom = false;