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

List:       kde-commits
Subject:    KDE/kdepimlibs/kresources
From:       Will Stephenson <wstephenson () kde ! org>
Date:       2008-12-04 11:15:15
Message-ID: 1228389315.706076.16518.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 892405 by wstephens:

Fixes for https://bugzilla.novell.com/show_bug.cgi?id=441363
* Make loading the uid map file more robust, so that it does not crash if
a corrupt uid map file is encountered.
* Refuse to add mappings for empty strings
* Update test case


 M  +20 -10    idmapper.cpp  
 M  +4 -0      tests/idmappertest.cpp  


--- trunk/KDE/kdepimlibs/kresources/idmapper.cpp #892404:892405
@@ -115,8 +115,12 @@
   while ( !ts.atEnd() ) {
     line = ts.readLine( 1024 );
     QStringList parts = line.split( "\x02\x02", QString::KeepEmptyParts );
-    d->idMap.insert( parts[ 0 ], parts[ 1 ] );
-    d->fingerprintMap.insert( parts[ 0 ], parts[ 2 ] );
+    // sanity check; the uidmap file could be corrupted and
+    // QList doesn't like accessing invalid indexes
+    if ( parts.count() == 3 ) {
+      d->idMap.insert( parts[ 0 ], parts[ 1 ] );
+      d->fingerprintMap.insert( parts[ 0 ], parts[ 2 ] );
+    }
   }
 
   file.close();
@@ -157,17 +161,21 @@
 
 void IdMapper::setRemoteId( const QString &localId, const QString &remoteId )
 {
-  d->idMap.insert( localId, remoteId );
+  if ( !( localId.isEmpty() || remoteId.isEmpty() ) ) {
+    d->idMap.insert( localId, remoteId );
+  }
 }
 
 void IdMapper::removeRemoteId( const QString &remoteId )
 {
-  QMap<QString, QVariant>::Iterator it;
-  for ( it = d->idMap.begin(); it != d->idMap.end(); ++it ) {
-    if ( it.value().toString() == remoteId ) {
-      d->idMap.remove( it.key() );
-      d->fingerprintMap.remove( it.key() );
-      return;
+  if ( !remoteId.isEmpty( ) ) {
+    QMap<QString, QVariant>::Iterator it;
+    for ( it = d->idMap.begin(); it != d->idMap.end(); ++it ) {
+      if ( it.value().toString() == remoteId ) {
+        d->idMap.remove( it.key() );
+        d->fingerprintMap.remove( it.key() );
+        return;
+      }
     }
   }
 }
@@ -214,7 +222,9 @@
 
 void IdMapper::setFingerprint( const QString &localId, const QString &fingerprint )
 {
-  d->fingerprintMap.insert( localId, fingerprint );
+  if ( !( localId.isEmpty() || fingerprint.isEmpty() ) ) {
+    d->fingerprintMap.insert( localId, fingerprint );
+  }
 }
 
 QString IdMapper::fingerprint( const QString &localId ) const
--- trunk/KDE/kdepimlibs/kresources/tests/idmappertest.cpp #892404:892405
@@ -33,9 +33,13 @@
   KRES::IdMapper mapper( "test.uidmap" );
   mapper.setIdentifier( "testidentifier" );
 
+//  mapper.load();
+  //qDebug() << "Loaded.";
+
   mapper.setRemoteId( "foo", "bar" );
   mapper.setRemoteId( "yes", "klar" );
   mapper.setRemoteId( "no", "nee" );
+  mapper.setRemoteId( QString(), QString() );
 
   QString mapperAsString = "foo\tbar\t\r\nno\tnee\t\r\nyes\tklar\t\r\n";
 
[prev in list] [next in list] [prev in thread] [next in thread] 

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