From 78e503bc1d79bc4fc29bc9cbe1dfb68ae4d16acf Mon Sep 17 00:00:00 2001 From: наб Date: Tue, 12 Nov 2024 13:28:04 +0100 Subject: Turn unique_ptr into real deleter types (warnings now, UB in C++20) --- apt-pkg/contrib/gpgv.cc | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'apt-pkg/contrib/gpgv.cc') diff --git a/apt-pkg/contrib/gpgv.cc b/apt-pkg/contrib/gpgv.cc index 225acae88..9ab3e066e 100644 --- a/apt-pkg/contrib/gpgv.cc +++ b/apt-pkg/contrib/gpgv.cc @@ -28,14 +28,17 @@ #include /*}}}*/ -// syntactic sugar to wrap a raw pointer with a custom deleter in a std::unique_ptr -static std::unique_ptr make_unique_char(void *const str = nullptr) -{ - return {static_cast(str), &free}; +namespace { + struct FILEDeleter { + void operator()(FILE *p) { + fclose(p); + } + }; } -static std::unique_ptr make_unique_FILE(std::string const &filename, char const *const mode) + +static std::unique_ptr make_unique_FILE(std::string const &filename, char const *const mode) { - return {fopen(filename.c_str(), mode), &fclose}; + return {fopen(filename.c_str(), mode), {}}; } class LineBuffer /*{{{*/ @@ -207,9 +210,9 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG, } enum { DETACHED, CLEARSIGNED } releaseSignature = (FileGPG != File) ? DETACHED : CLEARSIGNED; - auto sig = make_unique_char(); - auto data = make_unique_char(); - auto conf = make_unique_char(); + std::unique_ptr sig; + std::unique_ptr data; + std::unique_ptr conf; // Dump the configuration so apt-key picks up the correct Dir values { -- cgit v1.2.3-70-g09d2