changeset:   3130:75fb72c6bc8f
tag:         tip
user:        Daniel Burrows <dburrows@debian.org>
date:        Wed Jul 29 08:28:37 2009 -0700
summary:     Make resolver objects created by empty constructors return end iterators from their get_*() routines instead of crashing.

diff -r 4b8a7d0e706d -r 75fb72c6bc8f src/generic/apt/aptitude_resolver_universe.h
--- a/src/generic/apt/aptitude_resolver_universe.h	Tue Jul 28 08:26:51 2009 -0700
+++ b/src/generic/apt/aptitude_resolver_universe.h	Wed Jul 29 08:28:37 2009 -0700
@@ -93,7 +93,10 @@
   /** \return The underlying APT package wrapped by this object. */
   pkgCache::PkgIterator get_pkg() const
   {
-    return pkgCache::PkgIterator(*cache, const_cast<pkgCache::Package *>(pkg));
+    if(cache == NULL)
+      return pkgCache::PkgIterator();
+    else
+      return pkgCache::PkgIterator(*cache, const_cast<pkgCache::Package *>(pkg));
   }
 
   // Note that it's not necessary to compare the cache along with the
@@ -198,13 +201,18 @@
    */
   pkgCache::PkgIterator get_pkg() const
   {
-    pkgCache &pcache(cache->GetCache());
+    if(cache == NULL)
+      return pkgCache::PkgIterator();
+    else
+      {
+	pkgCache &pcache(cache->GetCache());
 
-    if(is_version)
-      return pkgCache::PkgIterator(pcache,
-				   pcache.PkgP + (pcache.VerP[offset].ParentPkg));
-    else
-      return pkgCache::PkgIterator(pcache, pcache.PkgP + offset);
+	if(is_version)
+	  return pkgCache::PkgIterator(pcache,
+				       pcache.PkgP + (pcache.VerP[offset].ParentPkg));
+	else
+	  return pkgCache::PkgIterator(pcache, pcache.PkgP + offset);
+      }
   }
 
   /** \return The APT version wrapped by this object, or an end
@@ -212,12 +220,17 @@
    */
   pkgCache::VerIterator get_ver() const
   {
-    pkgCache &pcache(cache->GetCache());
+    if(cache == NULL)
+      return pkgCache::VerIterator();
+    else
+      {
+	pkgCache &pcache(cache->GetCache());
 
-    if(!is_version)
-      return pkgCache::VerIterator(pcache, 0);
-    else
-      return pkgCache::VerIterator(pcache, pcache.VerP + offset);
+	if(!is_version)
+	  return pkgCache::VerIterator(pcache, 0);
+	else
+	  return pkgCache::VerIterator(pcache, pcache.VerP + offset);
+      }
   }
 
   /** \return The APT ID of this version if it is a real version,
@@ -478,7 +491,10 @@
   /** \return The APT dependency associated with this abstract dependency. */
   pkgCache::DepIterator get_dep() const
   {
-    return pkgCache::DepIterator(cache->GetCache(), const_cast<pkgCache::Dependency *>(start));
+    if(cache == NULL)
+      return pkgCache::DepIterator();
+    else
+      return pkgCache::DepIterator(cache->GetCache(), const_cast<pkgCache::Dependency *>(start));
   }
 
   /** \return The APT Provides relationship associated with this
@@ -486,8 +502,11 @@
    */
   pkgCache::PrvIterator get_prv() const
   {
-    return pkgCache::PrvIterator(cache->GetCache(), const_cast<pkgCache::Provides *>(prv),
-				 (pkgCache::Version *)0);
+    if(cache == NULL)
+      return pkgCache::PrvIterator();
+    else
+      return pkgCache::PrvIterator(cache->GetCache(), const_cast<pkgCache::Provides *>(prv),
+				   (pkgCache::Version *)0);
   }
 
   /** \return \b true if the given version will resolve this dependency. */

