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

List:       kde-core-devel
Subject:    KDE/kdelibs/kdecore
From:       Andreas Pakulat <apaku () gmx ! de>
Date:       2008-07-07 22:24:58
Message-ID: 1215469498.463451.32344.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 829251 by apaku:

Apparently its not wise to use const_this->somemap.find() with
this->somemap.end(). The comparison is unequal even if find() doesn't find the
value in the map/hash. So the code tried to get the value of the entry, but the
entry was "end" and that crashed in Qt's QBasicAtomicInt.

I'm not sure why the const_this is needed here anyway, shouldn't a simple
const_iterator and ::constEnd() be sufficient too?

Anyway, fixes crash and including testcase, where a macro is included in the
string that is not present in the map.

BUG:165902
CCMAIL:kde-core-devel@kde.org


 M  +5 -0      tests/kmacroexpandertest.cpp  
 M  +5 -3      util/kmacroexpander.cpp  


--- trunk/KDE/kdelibs/kdecore/tests/kmacroexpandertest.cpp #829250:829251
@@ -115,6 +115,11 @@
 	s = "Title: %{file} %{url";
 	QCOMPARE(KMacroExpander::expandMacros(s, smap),
 		QLatin1String("Title: filename.txt %{url"));
+
+        s = " * Copyright (C) 2008 %{AUTHOR}";
+        smap.clear();
+        QCOMPARE(KMacroExpander::expandMacros(s, smap),
+                QLatin1String(" * Copyright (C) 2008 %{AUTHOR}"));
 }
 
 void
--- trunk/KDE/kdelibs/kdecore/util/kmacroexpander.cpp #829250:829251
@@ -59,6 +59,7 @@
         if (ec != QLatin1Char(0) ) {
             if (str.unicode()[pos] != ec)
                 goto nohit;
+            kDebug(9010) << "trying"<< str << "from" << pos << ":" << str.mid(pos);
             if (!(len = expandEscapedMacro( str, pos, rst )))
                 goto nohit;
         } else {
@@ -145,7 +146,7 @@
 {
     const KMacroMapExpander<QChar,VT> *const_this = this;
     typename QHash<QChar,VT>::const_iterator it = const_this->macromap.find(str[pos]);
-    if (it != macromap.end()) {
+    if (it != const_this->macromap.end()) {
        ret += it.value();
        return 1;
     }
@@ -199,7 +200,7 @@
     const KMacroMapExpander<QString,VT> *const_this = this;
     typename QHash<QString,VT>::const_iterator it = 
         const_this->macromap.find( str.mid( pos, sl ) );
-    if (it != macromap.end()) {
+    if (it != const_this->macromap.end()) {
         ret += it.value();
         return sl;
     }
@@ -210,6 +211,7 @@
 int
 KMacroMapExpander<QString,VT>::expandEscapedMacro( const QString &str, int pos, QStringList &ret )
 {
+    kDebug() << "Expanding qstring vt macro:" << str << pos;
     if (str.length() <= pos + 1)
       return 0;
 
@@ -237,7 +239,7 @@
     const KMacroMapExpander<QString,VT> *const_this = this;
     typename QHash<QString,VT>::const_iterator it =
         const_this->macromap.find( str.mid( rpos, sl ) );
-    if (it != macromap.end()) {
+    if (it != const_this->macromap.end()) {
         ret += it.value();
         return rsl;
     }
[prev in list] [next in list] [prev in thread] [next in thread] 

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