From 7c61a1e64153bac91431e1a72d946208dd61eb30 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 15 Aug 2012 19:15:19 +0300 Subject: [PATCH] Store lookup failures separately from the package map This ensures that every pointer in the package map is valid, avoiding the need to check them and preventing segfaults due to a forgotten check. --- source/builder.cpp | 2 +- source/packagemanager.cpp | 14 ++++++++------ source/packagemanager.h | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index f894de0..3ac4b28 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -259,7 +259,7 @@ int Builder::main() list package_details; for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i) { - if(!i->second || !i->second->is_prepared()) + if(!i->second->is_prepared()) continue; string line = i->second->get_name(); diff --git a/source/packagemanager.cpp b/source/packagemanager.cpp index 746755e..240bf60 100644 --- a/source/packagemanager.cpp +++ b/source/packagemanager.cpp @@ -59,6 +59,9 @@ void PackageManager::add_package(Package *pkg) Package *PackageManager::find_package(const string &name) { + if(not_found.count(name)) + return 0; + PackageMap::iterator i = packages.find(name); if(i!=packages.end()) return i->second; @@ -84,22 +87,21 @@ Package *PackageManager::find_package(const string &name) return i->second; } - Package *pkg = 0; try { // Package source not found - create a binary package string flags_str = run_pkgconfig(name, "flags"); vector flags = split(flags_str); - pkg = BinaryPackage::from_flags(builder, name, flags); + Package *pkg = BinaryPackage::from_flags(builder, name, flags); + packages.insert(PackageMap::value_type(name, pkg)); + return pkg; } catch(...) { builder.problem(name, "not found"); + not_found.insert(name); + return 0; } - - packages.insert(PackageMap::value_type(name, pkg)); - - return pkg; } string PackageManager::run_pkgconfig(const string &pkg, const string &what) diff --git a/source/packagemanager.h b/source/packagemanager.h index 2fbaca1..9fb373e 100644 --- a/source/packagemanager.h +++ b/source/packagemanager.h @@ -28,6 +28,7 @@ private: SearchPath binpkg_files; bool no_externals; PackageMap packages; + std::set not_found; bool env_set; public: -- 2.45.2