[winpr] add WINPR_ATTR_FORMAT_ARG

this macro declares the function argument (pos,arg) to be a printf
style format string and enables compiler checks for that.
This commit is contained in:
akallabeth 2023-08-25 12:14:09 +02:00 committed by akallabeth
parent 786279fd9f
commit 4e824b243f
9 changed files with 18 additions and 0 deletions

View File

@ -129,6 +129,8 @@ static void set_stream_id_for_buffer(struct libusb_transfer* transfer, UINT32 st
user_data->streamID = streamID;
#endif
}
WINPR_ATTR_FORMAT_ARG(3, 8)
static BOOL log_libusb_result_(wLog* log, DWORD lvl, const char* fmt, const char* fkt,
const char* file, size_t line, int error, ...)
{

View File

@ -52,6 +52,7 @@ struct rdp_aad
static BOOL get_encoded_rsa_params(wLog* wlog, rdpPrivateKey* key, char** e, char** n);
static BOOL generate_pop_key(rdpAad* aad);
WINPR_ATTR_FORMAT_ARG(2, 3)
static SSIZE_T stream_sprintf(wStream* s, const char* fmt, ...)
{
va_list ap;

View File

@ -1210,6 +1210,7 @@ void clearChannelError(rdpContext* context)
ResetEvent(context->channelErrorEvent);
}
WINPR_ATTR_FORMAT_ARG(3, 4)
void setChannelError(rdpContext* context, UINT errorNum, const char* format, ...)
{
va_list ap;

View File

@ -468,6 +468,7 @@ BOOL http_request_set_transfer_encoding(HttpRequest* request, TRANSFER_ENCODING
return TRUE;
}
WINPR_ATTR_FORMAT_ARG(2, 3)
static BOOL http_encode_print(wStream* s, const char* fmt, ...)
{
char* str;

View File

@ -290,6 +290,7 @@ static const char* tsg_state_to_string(TSG_STATE state)
}
}
WINPR_ATTR_FORMAT_ARG(3, 4)
static BOOL tsg_print(char** buffer, size_t* len, const char* fmt, ...)
{
int rc;

View File

@ -1257,6 +1257,7 @@ static const struct
const char skey[6];
} options = { "--pcap=", "--fast", "--port=", "--local-only", "--cert=", "--key=" };
WINPR_ATTR_FORMAT_ARG(2, 0)
static void print_entry(FILE* fp, const char* fmt, const char* what, size_t size)
{
char buffer[32] = { 0 };

View File

@ -47,6 +47,12 @@
#define WINPR_API
#endif
#if defined(__GNUC__) || defined(__clang__)
#define WINPR_ATTR_FORMAT_ARG(pos, args) __attribute__((__format__(__printf__, pos, args)))
#else
#define WINPR_ATTR_FORMAT_ARG(pos, args)
#endif
#if defined(__STDC__) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 202311L)
#define WINPR_DEPRECATED(obj) [[deprecated]] obj
#define WINPR_DEPRECATED_VAR(text, obj) [[deprecated(text)]] obj

View File

@ -142,6 +142,7 @@ BOOL winpr_str_append(const char* what, char* buffer, size_t size, const char* s
return TRUE;
}
WINPR_ATTR_FORMAT_ARG(3, 4)
int winpr_asprintf(char** s, size_t* slen, const char* templ, ...)
{
va_list ap;

View File

@ -346,6 +346,7 @@ BOOL Stream_CheckAndLogRequiredCapacityExVa(const char* tag, DWORD level, wStrea
return TRUE;
}
WINPR_ATTR_FORMAT_ARG(6, 0)
BOOL Stream_CheckAndLogRequiredCapacityWLogExVa(wLog* log, DWORD level, wStream* s, size_t nmemb,
size_t size, const char* fmt, va_list args)
{
@ -369,6 +370,7 @@ BOOL Stream_CheckAndLogRequiredCapacityWLogExVa(wLog* log, DWORD level, wStream*
return TRUE;
}
WINPR_ATTR_FORMAT_ARG(6, 7)
BOOL Stream_CheckAndLogRequiredCapacityWLogEx(wLog* log, DWORD level, wStream* s, size_t nmemb,
size_t size, const char* fmt, ...)
{
@ -389,6 +391,7 @@ BOOL Stream_CheckAndLogRequiredCapacityWLogEx(wLog* log, DWORD level, wStream* s
return TRUE;
}
WINPR_ATTR_FORMAT_ARG(6, 7)
BOOL Stream_CheckAndLogRequiredLengthEx(const char* tag, DWORD level, wStream* s, size_t nmemb,
size_t size, const char* fmt, ...)
{
@ -439,6 +442,7 @@ BOOL Stream_CheckAndLogRequiredLengthWLogEx(wLog* log, DWORD level, wStream* s,
return TRUE;
}
WINPR_ATTR_FORMAT_ARG(6, 0)
BOOL Stream_CheckAndLogRequiredLengthWLogExVa(wLog* log, DWORD level, wStream* s, size_t nmemb,
size_t size, const char* fmt, va_list args)
{