diff options
author | Cameron Cawley | 2019-12-01 21:26:42 +0000 |
---|---|---|
committer | Filippos Karapetis | 2019-12-02 11:04:57 +0200 |
commit | e2d91258b7bfb989dc099f516bb31ceb44554529 (patch) | |
tree | 2bc300f76be4d4c8294789ea78beba12da5af21f | |
parent | a0c15492b41216d51903b20b2c4f2784fee7b08e (diff) | |
download | scummvm-rg350-e2d91258b7bfb989dc099f516bb31ceb44554529.tar.gz scummvm-rg350-e2d91258b7bfb989dc099f516bb31ceb44554529.tar.bz2 scummvm-rg350-e2d91258b7bfb989dc099f516bb31ceb44554529.zip |
PLUGINS: Fix crash when no plugins are available
-rw-r--r-- | backends/plugins/elf/elf-provider.cpp | 18 | ||||
-rw-r--r-- | base/plugins.cpp | 21 |
2 files changed, 22 insertions, 17 deletions
diff --git a/backends/plugins/elf/elf-provider.cpp b/backends/plugins/elf/elf-provider.cpp index 28536eee94..6d461c79df 100644 --- a/backends/plugins/elf/elf-provider.cpp +++ b/backends/plugins/elf/elf-provider.cpp @@ -181,15 +181,17 @@ PluginList ELFPluginProvider::getPlugins() { PluginList pl = FilePluginProvider::getPlugins(); #if defined(UNCACHED_PLUGINS) && !defined(ELF_NO_MEM_MANAGER) - // This static downcast is safe because all of the plugins must - // be ELF plugins - for (PluginList::iterator p = pl.begin(); p != pl.end(); ++p) { - (static_cast<ELFPlugin *>(*p))->trackSize(); - } + if (!pl.empty()) { + // This static downcast is safe because all of the plugins must + // be ELF plugins + for (PluginList::iterator p = pl.begin(); p != pl.end(); ++p) { + (static_cast<ELFPlugin *>(*p))->trackSize(); + } - // The Memory Manager should now allocate space based on the information - // it collected - ELFMemMan.allocateHeap(); + // The Memory Manager should now allocate space based on the information + // it collected + ELFMemMan.allocateHeap(); + } #endif return pl; diff --git a/base/plugins.cpp b/base/plugins.cpp index d5733599be..490ca33821 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -641,15 +641,18 @@ const Plugin *EngineManager::findPlugin(const Common::String &engineId) const { } // We failed to find it using the engine ID. Scan the list of plugins - PluginMan.loadFirstPlugin(); - do { - plugin = findLoadedPlugin(engineId); - if (plugin) { - // Update with new plugin file name - PluginMan.updateConfigWithFileName(engineId); - return plugin; - } - } while (PluginMan.loadNextPlugin()); + const PluginList &plugins = getPlugins(); + if (!plugins.empty()) { + PluginMan.loadFirstPlugin(); + do { + plugin = findLoadedPlugin(engineId); + if (plugin) { + // Update with new plugin file name + PluginMan.updateConfigWithFileName(engineId); + return plugin; + } + } while (PluginMan.loadNextPlugin()); + } return 0; } |