replace stdarg.h with cstdarg

The former was deprecated in C++14. The Standard says they are the same:

The contents of the header<cstdarg>are the same as the C standard library
header<stdarg.h>, with the following changes: The restrictions that ISO C
places on the second parameter to the va_start macro in header<stdarg.h>
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 <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2020-03-12 16:31:17 -07:00
parent 69a51e12c9
commit c846ee0d1b
No known key found for this signature in database
GPG Key ID: 36D31CFA845F0E3B
11 changed files with 36 additions and 33 deletions

View File

@ -30,7 +30,7 @@ static constexpr Domain exception_domain("exception");
void void
LogFormatV(LogLevel level, const Domain &domain, LogFormatV(LogLevel level, const Domain &domain,
const char *fmt, va_list ap) noexcept const char *fmt, std::va_list ap) noexcept
{ {
char msg[1024]; char msg[1024];
vsnprintf(msg, sizeof(msg), fmt, ap); vsnprintf(msg, sizeof(msg), fmt, ap);
@ -40,7 +40,7 @@ LogFormatV(LogLevel level, const Domain &domain,
void void
LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(level, domain, fmt, ap); LogFormatV(level, domain, fmt, ap);
va_end(ap); va_end(ap);
@ -49,7 +49,7 @@ LogFormat(LogLevel level, const Domain &domain, const char *fmt, ...) noexcept
void void
FormatDebug(const Domain &domain, const char *fmt, ...) noexcept FormatDebug(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(LogLevel::DEBUG, domain, fmt, ap); LogFormatV(LogLevel::DEBUG, domain, fmt, ap);
va_end(ap); va_end(ap);
@ -58,7 +58,7 @@ FormatDebug(const Domain &domain, const char *fmt, ...) noexcept
void void
FormatInfo(const Domain &domain, const char *fmt, ...) noexcept FormatInfo(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(LogLevel::INFO, domain, fmt, ap); LogFormatV(LogLevel::INFO, domain, fmt, ap);
va_end(ap); va_end(ap);
@ -67,7 +67,7 @@ FormatInfo(const Domain &domain, const char *fmt, ...) noexcept
void void
FormatDefault(const Domain &domain, const char *fmt, ...) noexcept FormatDefault(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(LogLevel::DEFAULT, domain, fmt, ap); LogFormatV(LogLevel::DEFAULT, domain, fmt, ap);
va_end(ap); va_end(ap);
@ -76,7 +76,7 @@ FormatDefault(const Domain &domain, const char *fmt, ...) noexcept
void void
FormatWarning(const Domain &domain, const char *fmt, ...) noexcept FormatWarning(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(LogLevel::WARNING, domain, fmt, ap); LogFormatV(LogLevel::WARNING, domain, fmt, ap);
va_end(ap); va_end(ap);
@ -85,7 +85,7 @@ FormatWarning(const Domain &domain, const char *fmt, ...) noexcept
void void
FormatError(const Domain &domain, const char *fmt, ...) noexcept FormatError(const Domain &domain, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(LogLevel::ERROR, domain, fmt, ap); LogFormatV(LogLevel::ERROR, domain, fmt, ap);
va_end(ap); va_end(ap);
@ -107,7 +107,7 @@ void
LogFormat(LogLevel level, const std::exception &e, const char *fmt, ...) noexcept LogFormat(LogLevel level, const std::exception &e, const char *fmt, ...) noexcept
{ {
char msg[1024]; char msg[1024];
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap); vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap); va_end(ap);
@ -132,7 +132,7 @@ void
LogFormat(LogLevel level, const std::exception_ptr &ep, const char *fmt, ...) noexcept LogFormat(LogLevel level, const std::exception_ptr &ep, const char *fmt, ...) noexcept
{ {
char msg[1024]; char msg[1024];
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(msg, sizeof(msg), fmt, ap); vsnprintf(msg, sizeof(msg), fmt, ap);
va_end(ap); va_end(ap);
@ -153,7 +153,7 @@ LogErrno(const Domain &domain, const char *msg) noexcept
} }
static void 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]; char msg[1024];
vsnprintf(msg, sizeof(msg), fmt, ap); vsnprintf(msg, sizeof(msg), fmt, ap);
@ -164,7 +164,7 @@ FormatErrnoV(const Domain &domain, int e, const char *fmt, va_list ap) noexcept
void void
FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept FormatErrno(const Domain &domain, int e, const char *fmt, ...) noexcept
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
FormatErrnoV(domain, e, fmt, ap); FormatErrnoV(domain, e, fmt, ap);
va_end(ap); va_end(ap);
@ -175,7 +175,7 @@ FormatErrno(const Domain &domain, const char *fmt, ...) noexcept
{ {
const int e = errno; const int e = errno;
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
FormatErrnoV(domain, e, fmt, ap); FormatErrnoV(domain, e, fmt, ap);
va_end(ap); va_end(ap);

View File

@ -22,10 +22,10 @@
#include "Log.hxx" // IWYU pragma: export #include "Log.hxx" // IWYU pragma: export
#include <stdarg.h> #include <cstdarg>
void void
LogFormatV(LogLevel level, const Domain &domain, LogFormatV(LogLevel level, const Domain &domain,
const char *fmt, va_list ap) noexcept; const char *fmt, std::va_list ap) noexcept;
#endif /* LOG_H */ #endif /* LOG_H */

View File

@ -36,7 +36,7 @@ LogListener::OnLog(JNIEnv *env, int priority,
assert(method); assert(method);
va_list args; std::va_list args;
va_start(args, fmt); va_start(args, fmt);
const auto log = FormatStringV(fmt, args); const auto log = FormatStringV(fmt, args);
va_end(args); va_end(args);

View File

@ -41,7 +41,7 @@ Response::Write(const char *data) noexcept
} }
bool 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()); return Write(FormatStringV(fmt, args).c_str());
} }
@ -49,7 +49,7 @@ Response::FormatV(const char *fmt, va_list args) noexcept
bool bool
Response::Format(const char *fmt, ...) noexcept Response::Format(const char *fmt, ...) noexcept
{ {
va_list args; std::va_list args;
va_start(args, fmt); va_start(args, fmt);
bool success = FormatV(fmt, args); bool success = FormatV(fmt, args);
va_end(args); va_end(args);
@ -78,7 +78,7 @@ Response::FormatError(enum ack code, const char *fmt, ...) noexcept
Format("ACK [%i@%u] {%s} ", Format("ACK [%i@%u] {%s} ",
(int)code, list_index, command); (int)code, list_index, command);
va_list args; std::va_list args;
va_start(args, fmt); va_start(args, fmt);
FormatV(fmt, args); FormatV(fmt, args);
va_end(args); va_end(args);

View File

@ -23,8 +23,9 @@
#include "protocol/Ack.hxx" #include "protocol/Ack.hxx"
#include "util/Compiler.h" #include "util/Compiler.h"
#include <cstdarg>
#include <stddef.h> #include <stddef.h>
#include <stdarg.h>
template<typename T> struct ConstBuffer; template<typename T> struct ConstBuffer;
class Client; class Client;
@ -74,7 +75,7 @@ public:
bool Write(const void *data, size_t length) noexcept; bool Write(const void *data, size_t length) noexcept;
bool Write(const char *data) 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; bool Format(const char *fmt, ...) noexcept;
static constexpr size_t MAX_BINARY_SIZE = 8192; static constexpr size_t MAX_BINARY_SIZE = 8192;

View File

@ -30,7 +30,8 @@
#include "BufferedOutputStream.hxx" #include "BufferedOutputStream.hxx"
#include "OutputStream.hxx" #include "OutputStream.hxx"
#include <stdarg.h> #include <cstdarg>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -85,7 +86,7 @@ BufferedOutputStream::Format(const char *fmt, ...)
} }
/* format into the buffer */ /* format into the buffer */
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
size_t size = vsnprintf(r.data, r.size, fmt, ap); size_t size = vsnprintf(r.data, r.size, fmt, ap);
va_end(ap); va_end(ap);

View File

@ -47,7 +47,7 @@ FfmpegImportLogLevel(int level) noexcept
} }
void 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; const AVClass * cls = nullptr;

View File

@ -20,9 +20,9 @@
#ifndef MPD_FFMPEG_LOG_CALLBACK_HXX #ifndef MPD_FFMPEG_LOG_CALLBACK_HXX
#define MPD_FFMPEG_LOG_CALLBACK_HXX #define MPD_FFMPEG_LOG_CALLBACK_HXX
#include <stdarg.h> #include <cstdarg>
void 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 #endif

View File

@ -21,8 +21,9 @@
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "LogV.hxx" #include "LogV.hxx"
#include <cstdarg>
#include <unistd.h> #include <unistd.h>
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -52,7 +53,7 @@ FatalError(const char *msg)
void void
FormatFatalError(const char *fmt, ...) FormatFatalError(const char *fmt, ...)
{ {
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
LogFormatV(LogLevel::ERROR, fatal_error_domain, fmt, ap); LogFormatV(LogLevel::ERROR, fatal_error_domain, fmt, ap);
va_end(ap); va_end(ap);
@ -91,7 +92,7 @@ void
FormatFatalSystemError(const char *fmt, ...) FormatFatalSystemError(const char *fmt, ...)
{ {
char buffer[1024]; char buffer[1024];
va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, ap); vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap); va_end(ap);

View File

@ -24,9 +24,9 @@
#include <stdlib.h> #include <stdlib.h>
AllocatedString<> 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); va_copy(tmp, args);
const int length = vsnprintf(nullptr, 0, fmt, tmp); const int length = vsnprintf(nullptr, 0, fmt, tmp);
va_end(tmp); va_end(tmp);
@ -43,7 +43,7 @@ FormatStringV(const char *fmt, va_list args) noexcept
AllocatedString<> AllocatedString<>
FormatString(const char *fmt, ...) noexcept FormatString(const char *fmt, ...) noexcept
{ {
va_list args; std::va_list args;
va_start(args, fmt); va_start(args, fmt);
auto p = FormatStringV(fmt, args); auto p = FormatStringV(fmt, args);
va_end(args); va_end(args);

View File

@ -22,7 +22,7 @@
#include "Compiler.h" #include "Compiler.h"
#include <stdarg.h> #include <cstdarg>
template<typename T> class AllocatedString; template<typename T> class AllocatedString;
@ -32,7 +32,7 @@ template<typename T> class AllocatedString;
*/ */
gcc_nonnull_all gcc_nonnull_all
AllocatedString<char> AllocatedString<char>
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 * Format into a newly allocated string. The caller frees the return