use pkgSrcRecords::Step() instead of Next()
[ntk/apt.git] / apt-pkg / cacheset.cc
index a58631d..2ed6a96 100644 (file)
@@ -391,6 +391,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                                                        CacheSetHelper &helper) {
        Version select = NEWEST;
        std::string str = cmdline;
+       if (unlikely(str.empty() == true))
+               return false;
        bool modifierPresent = false;
        unsigned short fallback = modID;
        for (std::list<Modifier>::const_iterator mod = mods.begin();
@@ -400,8 +402,8 @@ bool VersionContainerInterface::FromModifierCommandLine(unsigned short &modID,
                size_t const alength = strlen(mod->Alias);
                switch(mod->Pos) {
                case Modifier::POSTFIX:
-                       if (str.compare(str.length() - alength, alength,
-                                       mod->Alias, 0, alength) != 0)
+                       if (str.length() <= alength ||
+                             str.compare(str.length() - alength, alength, mod->Alias, 0, alength) != 0)
                                continue;
                        str.erase(str.length() - alength);
                        modID = mod->ID;
@@ -614,7 +616,7 @@ void CacheSetHelper::canNotFindFnmatch(PackageContainerInterface * const pci, pk
 }
 #endif                                                                 /*}}}*/
 // canNotFindPackage - handle the case no package is found from a string/*{{{*/
-void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
+APT_CONST void CacheSetHelper::canNotFindPackage(PackageContainerInterface * const /*pci*/, pkgCacheFile &/*Cache*/, std::string const &/*str*/) {
 }
                                                                        /*}}}*/
 // canNotFindAllVer                                                    /*{{{*/
@@ -663,24 +665,24 @@ pkgCache::VerIterator CacheSetHelper::canNotFindInstalledVer(pkgCacheFile &Cache
 }
                                                                        /*}}}*/
 // showTaskSelection                                                   /*{{{*/
-void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
+APT_CONST void CacheSetHelper::showTaskSelection(pkgCache::PkgIterator const &/*pkg*/,
                                       std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
 // showRegExSelection                                                  /*{{{*/
-void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
+APT_CONST void CacheSetHelper::showRegExSelection(pkgCache::PkgIterator const &/*pkg*/,
                                        std::string const &/*pattern*/) {
 }
                                                                        /*}}}*/
 #if (APT_PKG_MAJOR >= 4 && APT_PKG_MINOR >= 13)
 // showFnmatchSelection                                                        /*{{{*/
-void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &pkg,
+APT_CONST void CacheSetHelper::showFnmatchSelection(pkgCache::PkgIterator const &pkg,
                                           std::string const &pattern) {
 }
                                                                        /*}}}*/
 #endif
 // showSelectedVersion                                                 /*{{{*/
-void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
+APT_CONST void CacheSetHelper::showSelectedVersion(pkgCache::PkgIterator const &/*Pkg*/,
                                         pkgCache::VerIterator const /*Ver*/,
                                         std::string const &/*ver*/,
                                         bool const /*verIsRel*/) {