From 4e824b243f156073add54db10c509444dc3ac858 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Fri, 25 Aug 2023 12:14:09 +0200 Subject: [PATCH] [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. --- channels/urbdrc/client/libusb/libusb_udevice.c | 2 ++ libfreerdp/core/aad.c | 1 + libfreerdp/core/freerdp.c | 1 + libfreerdp/core/gateway/http.c | 1 + libfreerdp/core/gateway/tsg.c | 1 + server/Sample/sfreerdp.c | 1 + winpr/include/winpr/winpr.h | 6 ++++++ winpr/libwinpr/crt/string.c | 1 + winpr/libwinpr/utils/stream.c | 4 ++++ 9 files changed, 18 insertions(+) diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index ff37b039e..dd484352a 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -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, ...) { diff --git a/libfreerdp/core/aad.c b/libfreerdp/core/aad.c index 3e95cf170..f22e8b878 100644 --- a/libfreerdp/core/aad.c +++ b/libfreerdp/core/aad.c @@ -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; diff --git a/libfreerdp/core/freerdp.c b/libfreerdp/core/freerdp.c index b68bd07fd..7f7d3ac6f 100644 --- a/libfreerdp/core/freerdp.c +++ b/libfreerdp/core/freerdp.c @@ -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; diff --git a/libfreerdp/core/gateway/http.c b/libfreerdp/core/gateway/http.c index c5a663dee..6086e4f3a 100644 --- a/libfreerdp/core/gateway/http.c +++ b/libfreerdp/core/gateway/http.c @@ -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; diff --git a/libfreerdp/core/gateway/tsg.c b/libfreerdp/core/gateway/tsg.c index aa3fff099..a0d038d4c 100644 --- a/libfreerdp/core/gateway/tsg.c +++ b/libfreerdp/core/gateway/tsg.c @@ -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; diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index 58a36bbbe..036a4f74d 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -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 }; diff --git a/winpr/include/winpr/winpr.h b/winpr/include/winpr/winpr.h index 18c640a81..2e03fa2fb 100644 --- a/winpr/include/winpr/winpr.h +++ b/winpr/include/winpr/winpr.h @@ -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 diff --git a/winpr/libwinpr/crt/string.c b/winpr/libwinpr/crt/string.c index 553ce8ec1..58c486646 100644 --- a/winpr/libwinpr/crt/string.c +++ b/winpr/libwinpr/crt/string.c @@ -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; diff --git a/winpr/libwinpr/utils/stream.c b/winpr/libwinpr/utils/stream.c index c629e7ca8..c4ae25645 100644 --- a/winpr/libwinpr/utils/stream.c +++ b/winpr/libwinpr/utils/stream.c @@ -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) {