[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/kdepim/enterprise/kdepim/kmail
From:       Allen Winter <winter () kde ! org>
Date:       2010-10-10 18:44:37
Message-ID: 20101010184437.107D93E1F1 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1184538 by winterz:

fix crashing on 64-bit 
backport KMMsgBase::getLongPart() from KDE 4.4 

and also change KMFolderIndex::recreateIndex() to return a bool and don't set
mCompatable there.. it should only be set in createIndexFromContents() on success.
I think this one helps out with kolab/issue4498

MERGE: none (all this was backported from KDE4.4)


 M  +4 -8      kmfolderindex.cpp  
 M  +1 -1      kmfolderindex.h  
 M  +21 -18    kmmsgbase.cpp  


--- branches/kdepim/enterprise/kdepim/kmail/kmfolderindex.cpp #1184537:1184538
@@ -524,21 +524,17 @@
   return msgInfo;
 }
 
-void KMFolderIndex::recreateIndex( bool readIndexAfterwards )
+bool KMFolderIndex::recreateIndex()
 {
   kapp->setOverrideCursor(KCursor::arrowCursor());
   KMessageBox::information(0,
        i18n("The mail index for '%1' is corrupted and will be regenerated now, "
             "but some information, like status flags, might get lost.").arg(name()));
   kapp->restoreOverrideCursor();
-  createIndexFromContents();
-  if ( readIndexAfterwards ) {
-    readIndex();
+  if ( createIndexFromContents() != 0 ) {
+    return false;
   }
-
-  // Clear the corrupted flag
-  mCompactable = true;
-  writeConfig();
+  return readIndex();
 }
 
 void KMFolderIndex::silentlyRecreateIndex()
--- branches/kdepim/enterprise/kdepim/kmail/kmfolderindex.h #1184537:1184538
@@ -81,7 +81,7 @@
   virtual QString indexLocation() const;
   virtual int writeIndex( bool createEmptyIndex = false );
 
-  void recreateIndex( bool readIndexAfterwards = true );
+  bool recreateIndex();
   void silentlyRecreateIndex();
 
   /** Tests whether the contents of this folder is newer than the index.
--- branches/kdepim/enterprise/kdepim/kmail/kmmsgbase.cpp #1184537:1184538
@@ -1225,10 +1225,9 @@
 retry:
   off_t ret = 0;
 
-  g_chunk_offset = 0;
   bool using_mmap = false;
+  bool swapByteOrder = storage()->indexSwapByteOrder();
   int sizeOfLong = storage()->indexSizeOfLong();
-  bool swapByteOrder = storage()->indexSwapByteOrder();
   if (storage()->indexStreamBasePtr()) {
     if (g_chunk)
       free(g_chunk);
@@ -1247,30 +1246,30 @@
     fseek(storage()->mIndexStream, first_off, SEEK_SET);
   }
 
-  MsgPartType type;
-  Q_UINT16 l;
-  while (g_chunk_offset < mIndexLength) {
+  Q_UINT16 len;
+  for ( g_chunk_offset = 0; g_chunk_offset < mIndexLength; g_chunk_offset += len ) {
     Q_UINT32 tmp;
     copy_from_stream(tmp);
-    copy_from_stream(l);
+    copy_from_stream(len);
     if (swapByteOrder)
     {
        tmp = kmail_swap_32(tmp);
-       l = kmail_swap_16(l);
+       len = kmail_swap_16(len);
     }
-    type = (MsgPartType) tmp;
+    MsgPartType type = (MsgPartType) tmp;
 
-    if (g_chunk_offset + l > mIndexLength) {
-      kdDebug(5006) << "This should never happen.. " << __FILE__ << ":" << __LINE__ << endl;
+    if (g_chunk_offset + len > mIndexLength) {
+      kdDebug() << "This should never happen..";
       if(using_mmap) {
         g_chunk_length = 0;
         g_chunk = 0;
       }
-      storage()->recreateIndex();
+      if (!storage()->recreateIndex())
+        return 0;
       goto retry;
     }
     if(type == t) {
-      assert(sizeOfLong == l);
+      assert(sizeOfLong == len);
       if (sizeOfLong == sizeof(ret))
       {
 	 copy_from_stream(ret);
@@ -1301,7 +1300,7 @@
          if (!swapByteOrder)
          {
             // Index file order is the same as the order of this CPU.
-#ifndef WORDS_BIGENDIAN
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
             // Index file order is little endian
             ret = ret_1; // We drop the 4 most significant bytes
 #else
@@ -1312,13 +1311,15 @@
          else
          {
             // Index file order is different from this CPU.
-#ifndef WORDS_BIGENDIAN
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
             // Index file order is big endian
             ret = ret_2; // We drop the 4 most significant bytes
 #else
             // Index file order is little endian
             ret = ret_1; // We drop the 4 most significant bytes
 #endif
+
+
             // We swap the result to host order.
             ret = kmail_swap_32(ret);
          }
@@ -1326,16 +1327,16 @@
       }
       break;
     }
-    g_chunk_offset += l;
-  }
+  } // for
   if(using_mmap) {
     g_chunk_length = 0;
     g_chunk = 0;
   }
+
   return ret;
 }
 
-#ifndef WORDS_BIGENDIAN
+#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
 // We need to use swab to swap bytes to network byte order
 #define memcpy_networkorder(to, from, len)  swab((char *)(from), (char *)(to), len)
 #else
@@ -1343,7 +1344,8 @@
 #define memcpy_networkorder(to, from, len)  memcpy(to, from, len)
 #endif
 
-#define STORE_DATA_LEN(type, x, len, network_order) do { \
+#define STORE_DATA_LEN(type, x, len, network_order) \
+  do { \
 	int len2 = (len > 256) ? 256 : len; \
 	if(csize < (length + (len2 + sizeof(short) + sizeof(MsgPartType)))) \
     	   ret = (uchar *)realloc(ret, csize += len2+sizeof(short)+sizeof(MsgPartType)); \
@@ -1355,6 +1357,7 @@
            memcpy(ret+length+sizeof(t)+sizeof(l), x, len2); \
         length += len2+sizeof(t)+sizeof(l); \
     } while(0)
+
 #define STORE_DATA(type, x) STORE_DATA_LEN(type, &x, sizeof(x), false)
 
 //-----------------------------------------------------------------------------
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic