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-sortpkgs.cc | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'cmdline/apt-sortpkgs.cc') 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