[patch] deal with possible dereference of end iterator

Erik Hovland erik at hovland.org
Fri Dec 1 20:12:06 UTC 2006


Dereferencing an iterator that is actuall list.end() is undefined in C++
and generally leads to a segfault. I found one of those and saw it was
producing a warning. Chances are no one has ever reported that warning.
But just in case I made the function return if the iterator is end.

Patch attached.

E

-- 
Erik Hovland
mail: erik AT hovland DOT org
web: http://hovland.org/
PGP/GPG public key available on request
-------------- next part --------------
Fixes a case where an iterator might be an end() iterator and could
be dereferenced.

Signed-off-by: Erik Hovland <erik at hovland.org>

---

 src/pluginmanager.cpp |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/pluginmanager.cpp b/src/pluginmanager.cpp
index 3447cfc..2b749c6 100644
--- a/src/pluginmanager.cpp
+++ b/src/pluginmanager.cpp
@@ -151,8 +151,10 @@ PluginManager::getService( const Plugin*
     //search plugin in store
     vector<StoreItem>::const_iterator iter = lookupPlugin( plugin );
 
-    if ( iter == m_store.end() )
+    if ( iter == m_store.end() ) {
         warning() << k_funcinfo << "Plugin not found in store.\n";
+	return 0;
+    }
 
     return (*iter).service;
 }


More information about the Amarok mailing list