File r890868-quote-indicator-crash.diff of Package kdepim4

Subject: Fix crash on changing quote indicator
From: wstephenson@suse.de
Bug: kde#174268
Patch-Upstream: 890868
Index: kmail/kmmessage.cpp
===================================================================
--- kmail/kmmessage.cpp	(revision 890867)
+++ kmail/kmmessage.cpp	(revision 890868)
@@ -430,21 +430,22 @@
 
 
 //-----------------------------------------------------------------------------
-QString KMMessage::formatString(const QString& aStr) const
+QString KMMessage::formatString( const QString &aStr ) const
 {
   QString result, str;
   QChar ch;
   uint j;
 
-  if (aStr.isEmpty())
+  if ( aStr.isEmpty() ) {
     return aStr;
+  }
 
-  unsigned int strLength(aStr.length());
-  for (uint i=0; i<strLength;) {
+  unsigned int strLength( aStr.length() );
+  for ( uint i=0; i<strLength; ) {
     ch = aStr[i++];
-    if (ch == '%') {
+    if ( ch == '%' && i<strLength ) {
       ch = aStr[i++];
-      switch (ch.toLatin1()) {
+      switch ( ch.toLatin1() ) {
       case 'D':
         /* I'm not too sure about this change. Is it not possible
            to have a long form of the date used? I don't
@@ -465,15 +466,17 @@
 
         for (j=0; str[j]>' '; j++)
           ;
-        unsigned int strLength(str.length());
-        for (; j < strLength && str[j] <= ' '; j++)
+        unsigned int strLength( str.length() );
+        for ( ; j < strLength && str[j] <= ' '; j++ )
           ;
         result += str[0];
-        if (str[j]>' ')
+        if ( str[j] > ' ' ) {
           result += str[j];
-        else
-          if (str[1]>' ')
+        } else {
+          if ( str[1] > ' ' ) {
             result += str[1];
+          }
+        }
       }
       break;
       case 'T':
@@ -505,8 +508,9 @@
         result += ch;
         break;
       }
-    } else
+    } else {
       result += ch;
+    }
   }
   return result;
 }
openSUSE Build Service is sponsored by