OSDN Git Service

PATCH: [ 1528987 ] Use 64-bit variable as file position in Bytecompare
authorKimmo Varis <kimmov@gmail.com>
Thu, 27 Jul 2006 10:41:24 +0000 (10:41 +0000)
committerKimmo Varis <kimmov@gmail.com>
Thu, 27 Jul 2006 10:41:24 +0000 (10:41 +0000)
Src/ByteComparator.cpp
Src/ByteComparator.h
Src/Changes.txt
Src/DiffWrapper.cpp
Src/FileTextStats.h

index a922244..525adbc 100644 (file)
@@ -50,7 +50,7 @@ static inline bool iswsch(TCHAR ch)
  * @param [in] offset Byte offset in whole file (among several buffers).
  */
 static void TextScan(FileTextStats & stats, LPCSTR ptr, LPCSTR end, bool eof,
-       bool crflag, int offset)
+       bool crflag, __int64 offset)
 {
        LPCSTR start = ptr; // remember for recording zero-byte offsets
 
@@ -73,7 +73,7 @@ static void TextScan(FileTextStats & stats, LPCSTR ptr, LPCSTR end, bool eof,
                if (ch == 0)
                {
                        ++stats.nzeros;
-                       int index = offset + (ptr - start);
+                       __int64 index = offset + (ptr - start);
                        if (stats.first_zero == -1)
                                stats.first_zero = index;
                        stats.last_zero = index;
@@ -161,7 +161,7 @@ ByteComparator::ByteComparator(int ignore_case, int ignore_space_change,
  */
 ByteComparator::COMP_RESULT ByteComparator::CompareBuffers(
        FileTextStats & stats0, FileTextStats & stats1, LPCSTR &ptr0, LPCSTR &ptr1,
-       LPCSTR end0, LPCSTR end1, bool eof0, bool eof1, int offset0, int offset1)
+       LPCSTR end0, LPCSTR end1, bool eof0, bool eof1, __int64 offset0, __int64 offset1)
 {
        // First, update file text statistics by doing a full scan
        // for 0s and all types of line delimiters
index 31294a5..b1a3d06 100644 (file)
@@ -40,7 +40,7 @@ public:
 
        COMP_RESULT CompareBuffers(FileTextStats & stats0, FileTextStats & stats1,
                LPCSTR &ptr0, LPCSTR &ptr1, LPCSTR end0, LPCSTR end1, bool eof0, bool eof1,
-               int offset0, int offset1);
+               __int64 offset0, __int64 offset1);
 
 private:
        // settings
index d3c5a25..f542897 100644 (file)
@@ -5,6 +5,8 @@ Add new items to top.
 2006-07-27 Kimmo
  PATCH: [ 1528841 ] Cleanup ByteComparator
   Src: ByteComparator.cpp ByteComparator.h FileTextStats.h
+ PATCH: [ 1528987 ] Use 64-bit variable as file position in Bytecompare
+  Src: ByteComparator.cpp ByteComparator.h DiffWrapper.cpp FileTextStats.h
 
 2006-07-26 Kimmo
  PATCH: [ 1528444 ] Cleanup for AppSerialize
index 398e6c3..b3fbab8 100644 (file)
@@ -1920,8 +1920,8 @@ int DiffFileData::byte_compare_files(BOOL bStopAfterFirstDiff, const IAbortable
        }
 
        // area of buffer currently holding data
-       int bfstart[2]; // offset into buff[i] where current data resides
-       int bfend[2]; // past-the-end pointer into buff[i], giving end of current data
+       __int64 bfstart[2]; // offset into buff[i] where current data resides
+       __int64 bfend[2]; // past-the-end pointer into buff[i], giving end of current data
        // buff[0] has bytes to process from buff[0][bfstart[0]] to buff[0][bfend[0]-1]
 
        bool eof[2]; // if we've finished file
@@ -1955,8 +1955,9 @@ int DiffFileData::byte_compare_files(BOOL bStopAfterFirstDiff, const IAbortable
                        }
                        if (!eof[i] && bfend[i]<countof(buff[i])-1)
                        {
-                               int space = countof(buff[i]) - bfend[i];
-                               int rtn = fread(&buff[i][bfend[i]], 1, space, fp[i]);
+                               // Assume our blocks are in range of unsigned int
+                               unsigned int space = countof(buff[i]) - bfend[i];
+                               size_t rtn = fread(&buff[i][bfend[i]], 1, space, fp[i]);
                                if (ferror(fp[i]))
                                        return DIFFCODE::CMPERR;
                                if (feof(fp[i]))
@@ -1976,8 +1977,8 @@ int DiffFileData::byte_compare_files(BOOL bStopAfterFirstDiff, const IAbortable
                LPCSTR end0 = &buff[0][bfend[0]];
                LPCSTR end1 = &buff[1][bfend[1]];
 
-               int offset0 = (ptr0 - &buff[0][0]);
-               int offset1 = (ptr1 - &buff[1][0]);
+               __int64 offset0 = (ptr0 - &buff[0][0]);
+               __int64 offset1 = (ptr1 - &buff[1][0]);
 
                // are these two buffers the same?
                if (!comparator.CompareBuffers(m_textStats0, m_textStats1, 
index 1573ba7..4095676 100644 (file)
  */
 struct FileTextStats
 {
-       int ncrs; /**< Count of MAC (CR-byte) EOLs. */
-       int nlfs; /**< Count of Unix (LF-byte) EOLs. */
-       int ncrlfs; /**< Count of DOS (CR+LF-bytes) EOLs. */
-       int nzeros; /**< Count of zero-bytes. */
-       int first_zero; /**< Byte offset to first zero-byte, initially -1 */
-       int last_zero; /**< Byte offset to last zero-byte, initially -1 */
-       int nlosses;
+       unsigned int ncrs; /**< Count of MAC (CR-byte) EOLs. */
+       unsigned int nlfs; /**< Count of Unix (LF-byte) EOLs. */
+       unsigned int ncrlfs; /**< Count of DOS (CR+LF-bytes) EOLs. */
+       unsigned int nzeros; /**< Count of zero-bytes. */
+       __int64 first_zero; /**< Byte offset to first zero-byte, initially -1 */
+       __int64 last_zero; /**< Byte offset to last zero-byte, initially -1 */
+       unsigned int nlosses;
        FileTextStats() { clear(); }
        void clear() { ncrs = nlfs = ncrlfs = nzeros = nlosses = 0; first_zero = -1; last_zero = -1; }
 };