diff options
author | David Kalnischkies <david@kalnischkies.de> | 2015-09-12 10:35:49 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2015-09-14 15:22:19 +0200 |
commit | 7414af7fa88164209eec9c585b8d175c1618ecbc (patch) | |
tree | 2a582637043bd8c57d43bf8b193dd9ecb479d559 /cmdline | |
parent | 7c4f1ca5fe315a8223570b05994d6d7ca7c55c4f (diff) | |
download | apt-7414af7fa88164209eec9c585b8d175c1618ecbc.tar.gz |
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
Diffstat (limited to 'cmdline')
-rw-r--r-- | cmdline/apt-cache.cc | 7 | ||||
-rw-r--r-- | cmdline/apt-dump-solver.cc | 3 | ||||
-rw-r--r-- | cmdline/apt-helper.cc | 6 | ||||
-rw-r--r-- | cmdline/apt-sortpkgs.cc | 18 |
4 files changed, 13 insertions, 21 deletions
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 <stdio.h> #include <iostream> #include <string> +#include <memory> #include <apti18n.h> /*}}}*/ @@ -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<unsigned char[]>(new unsigned char[Largest+1]); for (vector<PkgName>::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; } /*}}}*/ |