From c846ee0d1b603e141fc536078b920caedae3bf6f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 12 Mar 2020 16:31:17 -0700 Subject: [PATCH] replace stdarg.h with cstdarg The former was deprecated in C++14. The Standard says they are the same: The contents of the headerare the same as the C standard library header, with the following changes: The restrictions that ISO C places on the second parameter to the va_start macro in header are different in this International Standard. The parameter parmN is the rightmost parameter in the variable parameter list of the function definition (the one just before the...).219If the parameter parmN is a pack expansion (17.5.3) or an entity resulting from a lambda capture (8.1.5), the program is ill-formed, no diagnostic required. If the parameter parmN is of a reference type, or of a type that is not compatible with the type that results when passing an argument for which there is no parameter, the behavior is undefined. Also changed va_list to the std:: namespace version, which is the same. Signed-off-by: Rosen Penev --- src/Log.cxx | 24 ++++++++++++------------ src/LogV.hxx | 4 ++-- src/android/LogListener.cxx | 2 +- src/client/Response.cxx | 6 +++--- src/client/Response.hxx | 5 +++-- src/fs/io/BufferedOutputStream.cxx | 5 +++-- src/lib/ffmpeg/LogCallback.cxx | 2 +- src/lib/ffmpeg/LogCallback.hxx | 4 ++-- src/system/FatalError.cxx | 7 ++++--- src/util/FormatString.cxx | 6 +++--- src/util/FormatString.hxx | 4 ++-- 11 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/Log.cxx b/src/Log.cxx index 41e4958bc..21fcdefb8 100644 --- a/src/Log.cxx +++ b/src/Log.cxx @@ -30,7 +30,7 @@ static constexpr Domain exception_domain("exception"); void LogFormatV(LogLevel level, const Domain &domain, - const char *fmt, va_list ap) noexcept + const char *fmt, std::va_list ap) noexcept { char msg[1024]; vsnprintf(msg, sizeof(msg), fmt, ap); @@ -40,7 +40,7 @@ LogFormatV(LogLevel level, const Domain &domain, void LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(level, domain, fmt, ap); va_end(ap); @@ -49,7 +49,7 @@ LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept void FormatDebug(const Domain &domain, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(LogLevel::DEBUG, domain, fmt, ap); va_end(ap); @@ -58,7 +58,7 @@ FormatDebug(const Domain &domain, const char *fmt, ...) noexcept void FormatInfo(const Domain &domain, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(LogLevel::INFO, domain, fmt, ap); va_end(ap); @@ -67,7 +67,7 @@ FormatInfo(const Domain &domain, const char *fmt, ...) noexcept void FormatDefault(const Domain &domain, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(LogLevel::DEFAULT, domain, fmt, ap); va_end(ap); @@ -76,7 +76,7 @@ FormatDefault(const Domain &domain, const char *fmt, ...) noexcept void FormatWarning(const Domain &domain, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(LogLevel::WARNING, domain, fmt, ap); va_end(ap); @@ -85,7 +85,7 @@ FormatWarning(const Domain &domain, const char *fmt, ...) noexcept void FormatError(const Domain &domain, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(LogLevel::ERROR, domain, fmt, ap); va_end(ap); @@ -107,7 +107,7 @@ void LogFormat(LogLevel level, const std::exception &e, const char *fmt, ...) noexcept { char msg[1024]; - va_list ap; + std::va_list ap; va_start(ap, fmt); vsnprintf(msg, sizeof(msg), fmt, ap); va_end(ap); @@ -132,7 +132,7 @@ void LogFormat(LogLevel level, const std::exception_ptr &ep, const char *fmt, ...) noexcept { char msg[1024]; - va_list ap; + std::va_list ap; va_start(ap, fmt); vsnprintf(msg, sizeof(msg), fmt, ap); va_end(ap); @@ -153,7 +153,7 @@ LogErrno(const Domain &domain, const char *msg) noexcept } static void -FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap) noexcept +FormatErrnoV(const Domain &domain, int e, const char *fmt, std::va_list ap) noexcept { char msg[1024]; vsnprintf(msg, sizeof(msg), fmt, ap); @@ -164,7 +164,7 @@ FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap) noexcept void FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept { - va_list ap; + std::va_list ap; va_start(ap, fmt); FormatErrnoV(domain, e, fmt, ap); va_end(ap); @@ -175,7 +175,7 @@ FormatErrno(const Domain &domain, const char *fmt, ...) noexcept { const int e = errno; - va_list ap; + std::va_list ap; va_start(ap, fmt); FormatErrnoV(domain, e, fmt, ap); va_end(ap); diff --git a/src/LogV.hxx b/src/LogV.hxx index 493f47d12..64ae193c8 100644 --- a/src/LogV.hxx +++ b/src/LogV.hxx @@ -22,10 +22,10 @@ #include "Log.hxx" // IWYU pragma: export -#include +#include void LogFormatV(LogLevel level, const Domain &domain, - const char *fmt, va_list ap) noexcept; + const char *fmt, std::va_list ap) noexcept; #endif /* LOG_H */ diff --git a/src/android/LogListener.cxx b/src/android/LogListener.cxx index 8e89f2129..a6156033d 100644 --- a/src/android/LogListener.cxx +++ b/src/android/LogListener.cxx @@ -36,7 +36,7 @@ LogListener::OnLog(JNIEnv *env, int priority, assert(method); - va_list args; + std::va_list args; va_start(args, fmt); const auto log = FormatStringV(fmt, args); va_end(args); diff --git a/src/client/Response.cxx b/src/client/Response.cxx index 207489fa6..7c8118e6f 100644 --- a/src/client/Response.cxx +++ b/src/client/Response.cxx @@ -41,7 +41,7 @@ Response::Write(const char *data) noexcept } bool -Response::FormatV(const char *fmt, va_list args) noexcept +Response::FormatV(const char *fmt, std::va_list args) noexcept { return Write(FormatStringV(fmt, args).c_str()); } @@ -49,7 +49,7 @@ Response::FormatV(const char *fmt, va_list args) noexcept bool Response::Format(const char *fmt, ...) noexcept { - va_list args; + std::va_list args; va_start(args, fmt); bool success = FormatV(fmt, args); va_end(args); @@ -78,7 +78,7 @@ Response::FormatError(enum ack code, const char *fmt, ...) noexcept Format("ACK [%i@%u] {%s} ", (int)code, list_index, command); - va_list args; + std::va_list args; va_start(args, fmt); FormatV(fmt, args); va_end(args); diff --git a/src/client/Response.hxx b/src/client/Response.hxx index f5898b16b..b2c72cf48 100644 --- a/src/client/Response.hxx +++ b/src/client/Response.hxx @@ -23,8 +23,9 @@ #include "protocol/Ack.hxx" #include "util/Compiler.h" +#include + #include -#include template struct ConstBuffer; class Client; @@ -74,7 +75,7 @@ public: bool Write(const void *data, size_t length) noexcept; bool Write(const char *data) noexcept; - bool FormatV(const char *fmt, va_list args) noexcept; + bool FormatV(const char *fmt, std::va_list args) noexcept; bool Format(const char *fmt, ...) noexcept; static constexpr size_t MAX_BINARY_SIZE = 8192; diff --git a/src/fs/io/BufferedOutputStream.cxx b/src/fs/io/BufferedOutputStream.cxx index 46249de0a..eb0d2d804 100644 --- a/src/fs/io/BufferedOutputStream.cxx +++ b/src/fs/io/BufferedOutputStream.cxx @@ -30,7 +30,8 @@ #include "BufferedOutputStream.hxx" #include "OutputStream.hxx" -#include +#include + #include #include @@ -85,7 +86,7 @@ BufferedOutputStream::Format(const char *fmt, ...) } /* format into the buffer */ - va_list ap; + std::va_list ap; va_start(ap, fmt); size_t size = vsnprintf(r.data, r.size, fmt, ap); va_end(ap); diff --git a/src/lib/ffmpeg/LogCallback.cxx b/src/lib/ffmpeg/LogCallback.cxx index 1e9bc3d99..d88f298d0 100644 --- a/src/lib/ffmpeg/LogCallback.cxx +++ b/src/lib/ffmpeg/LogCallback.cxx @@ -47,7 +47,7 @@ FfmpegImportLogLevel(int level) noexcept } void -FfmpegLogCallback(gcc_unused void *ptr, int level, const char *fmt, va_list vl) +FfmpegLogCallback(gcc_unused void *ptr, int level, const char *fmt, std::va_list vl) { const AVClass * cls = nullptr; diff --git a/src/lib/ffmpeg/LogCallback.hxx b/src/lib/ffmpeg/LogCallback.hxx index 08d8d2251..0896ea2f2 100644 --- a/src/lib/ffmpeg/LogCallback.hxx +++ b/src/lib/ffmpeg/LogCallback.hxx @@ -20,9 +20,9 @@ #ifndef MPD_FFMPEG_LOG_CALLBACK_HXX #define MPD_FFMPEG_LOG_CALLBACK_HXX -#include +#include void -FfmpegLogCallback(void *ptr, int level, const char *fmt, va_list vl); +FfmpegLogCallback(void *ptr, int level, const char *fmt, std::va_list vl); #endif diff --git a/src/system/FatalError.cxx b/src/system/FatalError.cxx index 7e195a7d2..f3e8b6e0c 100644 --- a/src/system/FatalError.cxx +++ b/src/system/FatalError.cxx @@ -21,8 +21,9 @@ #include "util/Domain.hxx" #include "LogV.hxx" +#include + #include -#include #include #include #include @@ -52,7 +53,7 @@ FatalError(const char *msg) void FormatFatalError(const char *fmt, ...) { - va_list ap; + std::va_list ap; va_start(ap, fmt); LogFormatV(LogLevel::ERROR, fatal_error_domain, fmt, ap); va_end(ap); @@ -91,7 +92,7 @@ void FormatFatalSystemError(const char *fmt, ...) { char buffer[1024]; - va_list ap; + std::va_list ap; va_start(ap, fmt); vsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); diff --git a/src/util/FormatString.cxx b/src/util/FormatString.cxx index c26702e75..3ae0986b1 100644 --- a/src/util/FormatString.cxx +++ b/src/util/FormatString.cxx @@ -24,9 +24,9 @@ #include AllocatedString<> -FormatStringV(const char *fmt, va_list args) noexcept +FormatStringV(const char *fmt, std::va_list args) noexcept { - va_list tmp; + std::va_list tmp; va_copy(tmp, args); const int length = vsnprintf(nullptr, 0, fmt, tmp); va_end(tmp); @@ -43,7 +43,7 @@ FormatStringV(const char *fmt, va_list args) noexcept AllocatedString<> FormatString(const char *fmt, ...) noexcept { - va_list args; + std::va_list args; va_start(args, fmt); auto p = FormatStringV(fmt, args); va_end(args); diff --git a/src/util/FormatString.hxx b/src/util/FormatString.hxx index cec827537..e1ecc8500 100644 --- a/src/util/FormatString.hxx +++ b/src/util/FormatString.hxx @@ -22,7 +22,7 @@ #include "Compiler.h" -#include +#include template class AllocatedString; @@ -32,7 +32,7 @@ template class AllocatedString; */ gcc_nonnull_all AllocatedString -FormatStringV(const char *fmt, va_list args) noexcept; +FormatStringV(const char *fmt, std::va_list args) noexcept; /** * Format into a newly allocated string. The caller frees the return