Fix possibly undefined behavior in basearch computation.
authorMichael Andres <ma@suse.de>
Wed, 4 Aug 2010 14:03:40 +0000 (16:03 +0200)
committerMichael Andres <ma@suse.de>
Wed, 4 Aug 2010 14:04:27 +0000 (16:04 +0200)
zypp/repo/RepoVariables.cc

index 51b0701..c93432c 100644 (file)
@@ -34,36 +34,21 @@ std::string RepoVariablesStringReplacer::operator()( const std::string &value )
   string newvalue(value);
 
   // $arch
-  newvalue = str::gsub( newvalue,
-                        "$arch",
-                        ZConfig::instance().systemArchitecture().asString() );
-  // $basearch
-
-  Arch::CompatSet cset( Arch::compatSet( ZConfig::instance().systemArchitecture() ) );
-  Arch::CompatSet::const_iterator it = cset.end();
-  --it;
-  // now at noarch
-  --it;
+  Arch sysarch( ZConfig::instance().systemArchitecture() );
+  newvalue = str::gsub( newvalue, "$arch", sysarch.asString() );
 
-  Arch basearch = *it;
-  if ( basearch == Arch_noarch )
+  // $basearch
+  Arch basearch( sysarch );
+  Arch::CompatSet cset( Arch::compatSet( sysarch ) );
+  if ( cset.size() > 2 )       // systemArchitecture, ..., basearch, noarch
   {
-    basearch = ZConfig::instance().systemArchitecture();
+    basearch = *(++++cset.rbegin());
   }
+  newvalue = str::gsub( newvalue, "$basearch", basearch.asString() );
 
-  newvalue = str::gsub( newvalue,
-                        "$basearch",
-                        basearch.asString() );
+  // $releasever (Target::distributionVersion assumes root=/ if target not initialized)
+  newvalue = str::gsub( newvalue, "$releasever", Target::distributionVersion(Pathname()/*guess*/) );
 
-  // only replace $releasever if the target is
-  // initialized
-  if ( getZYpp()->getTarget() )
-  {
-      newvalue = str::gsub( newvalue,
-                            "$releasever",
-                            getZYpp()->target()->distributionVersion() );
-  }
-  
   return newvalue;
 }