From 7414af7fa88164209eec9c585b8d175c1618ecbc Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 12 Sep 2015 10:35:49 +0200 Subject: various changes to increase test-coverage And of course, testing obscure things ends up showing obscure 'bugs' or better shortcomings/inconsitencies, so lets fix them with the tests. Git-Dch: Ignore --- cmdline/apt-cache.cc | 7 ++++--- cmdline/apt-dump-solver.cc | 3 ++- cmdline/apt-helper.cc | 6 +++--- cmdline/apt-sortpkgs.cc | 18 ++++-------------- 4 files changed, 13 insertions(+), 21 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cache.cc b/cmdline/apt-cache.cc index 1493b63dc..2db251350 100644 --- a/cmdline/apt-cache.cc +++ b/cmdline/apt-cache.cc @@ -312,13 +312,14 @@ static void ShowHashTableStats(std::string Type, /* */ static bool Stats(CommandLine &CmdL) { - pkgCacheFile CacheFile; - pkgCache *Cache = CacheFile.GetPkgCache(); - if (CmdL.FileSize() > 1) { _error->Error(_("apt-cache stats does not take any arguments")); return false; } + + pkgCacheFile CacheFile; + pkgCache *Cache = CacheFile.GetPkgCache(); + if (unlikely(Cache == NULL)) return false; diff --git a/cmdline/apt-dump-solver.cc b/cmdline/apt-dump-solver.cc index 2e352931f..47b515be5 100644 --- a/cmdline/apt-dump-solver.cc +++ b/cmdline/apt-dump-solver.cc @@ -53,7 +53,8 @@ int main(int argc,const char *argv[]) /*{{{*/ return 0; } - unlink(filename); + if (strcmp(filename, "/dev/null") != 0) + unlink(filename); FileFd input, output; if (input.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly) == false || output.Open(filename, FileFd::WriteOnly | FileFd::Create | FileFd::Exclusive, 0600) == false || diff --git a/cmdline/apt-helper.cc b/cmdline/apt-helper.cc index 2d24a8aee..dc4efb32b 100644 --- a/cmdline/apt-helper.cc +++ b/cmdline/apt-helper.cc @@ -81,7 +81,7 @@ static bool DoDownloadFile(CommandLine &CmdL) static bool DoSrvLookup(CommandLine &CmdL) { - if (CmdL.FileSize() < 1) + if (CmdL.FileSize() <= 1) return _error->Error("Must specify at least one SRV record"); for(size_t i = 1; CmdL.FileList[i] != NULL; ++i) @@ -95,10 +95,10 @@ static bool DoSrvLookup(CommandLine &CmdL) std::string const host = name.substr(0, found); size_t const port = atoi(name.c_str() + found + 1); if(GetSrvRecords(host, port, srv_records) == false) - _error->Warning(_("GetSrvRec failed for %s"), name.c_str()); + _error->Error(_("GetSrvRec failed for %s"), name.c_str()); } else if(GetSrvRecords(name, srv_records) == false) - _error->Warning(_("GetSrvRec failed for %s"), name.c_str()); + _error->Error(_("GetSrvRec failed for %s"), name.c_str()); for (SrvRec const &I : srv_records) c1out << I.target << "\t" << I.priority << "\t" << I.weight << "\t" << I.port << std::endl; diff --git a/cmdline/apt-sortpkgs.cc b/cmdline/apt-sortpkgs.cc index 12ef8dda0..cde3069bd 100644 --- a/cmdline/apt-sortpkgs.cc +++ b/cmdline/apt-sortpkgs.cc @@ -30,6 +30,7 @@ #include #include #include +#include #include /*}}}*/ @@ -112,32 +113,21 @@ static bool DoIt(string InFile) // Emit FileFd stdoutfd; stdoutfd.OpenDescriptor(STDOUT_FILENO, FileFd::WriteOnly, false); - unsigned char *Buffer = new unsigned char[Largest+1]; + auto const Buffer = std::unique_ptr(new unsigned char[Largest+1]); for (vector::iterator I = List.begin(); I != List.end(); ++I) { // Read in the Record. - if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer,I->Length) == false) - { - delete [] Buffer; + if (Fd.Seek(I->Offset) == false || Fd.Read(Buffer.get(),I->Length) == false) return false; - } Buffer[I->Length] = '\n'; - if (Section.Scan((char *)Buffer,I->Length+1) == false) - { - delete [] Buffer; + if (Section.Scan((char *)Buffer.get(),I->Length+1) == false) return _error->Error("Internal error, failed to scan buffer"); - } // Sort the section if (Section.Write(stdoutfd, Order) == false || stdoutfd.Write("\n", 1) == false) - { - delete [] Buffer; return _error->Error("Internal error, failed to sort fields"); - } } - - delete [] Buffer; return true; } /*}}}*/ -- cgit v1.2.3-70-g09d2