summaryrefslogtreecommitdiff
path: root/cmdline/apt-sortpkgs.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2015-09-12 10:35:49 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2015-09-14 15:22:19 +0200
commit7414af7fa88164209eec9c585b8d175c1618ecbc (patch)
tree2a582637043bd8c57d43bf8b193dd9ecb479d559 /cmdline/apt-sortpkgs.cc
parent7c4f1ca5fe315a8223570b05994d6d7ca7c55c4f (diff)
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/apt-sortpkgs.cc')
-rw-r--r--cmdline/apt-sortpkgs.cc18
1 files changed, 4 insertions, 14 deletions
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;
}
/*}}}*/