diff options
author | David Kalnischkies <david@kalnischkies.de> | 2020-06-28 20:52:09 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2021-02-04 11:00:00 +0100 |
commit | 96dc40b19623621a9cc2c5541fb3adbbceb553b1 (patch) | |
tree | 405ed81b2c23d21b52324b393c25301056011162 /apt-pkg/contrib/strutl.cc | |
parent | 35af71bc026d85aef4af979aa247e837d91dfc1c (diff) |
Replace PrintStatus with SendMessage usage
varg API is a nightmare as the symbols seems different on ever other
arch, but more importantly SendMessage does a few checks on the content
of the message and it is all outputted via C++ iostreams and not mixed
in FILE* which is handy for overriding the streams.
Diffstat (limited to 'apt-pkg/contrib/strutl.cc')
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 84e79122e..3a0a6eaa3 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -26,6 +26,7 @@ #include <limits> #include <locale> #include <sstream> +#include <memory> #include <sstream> #include <string> #include <vector> @@ -1414,13 +1415,12 @@ unsigned long RegexChoice(RxChoiceList *Rxs,const char **ListBegin, // --------------------------------------------------------------------- /* This is used to make the internationalization strings easier to translate and to allow reordering of parameters */ -static bool iovprintf(ostream &out, const char *format, +bool iovprintf(std::ostream &out, const char *format, va_list &args, ssize_t &size) { - char *S = (char*)malloc(size); - ssize_t const n = vsnprintf(S, size, format, args); + auto S = std::unique_ptr<char,decltype(&free)>{static_cast<char*>(malloc(size)), &free}; + ssize_t const n = vsnprintf(S.get(), size, format, args); if (n > -1 && n < size) { - out << S; - free(S); + out << S.get(); return true; } else { if (n > -1) @@ -1428,7 +1428,6 @@ static bool iovprintf(ostream &out, const char *format, else size *= 2; } - free(S); return false; } void ioprintf(ostream &out,const char *format,...) |