Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTON-2772: make wrong printf format strings a MSVC compile error #409

Merged
merged 2 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 47 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,59 @@ option(BUILD_TLS "Enable building separate TLS library for Proton raw connection
# Set any additional compiler specific flags
set (WERROR_GNU "-Werror")
set (WERROR_Clang "-Werror")
set (WERROR_MSVC "")
set (WERROR_MSVC "/WX")

set (COMMON_WARNING_GNU "-Wall -pedantic-errors")
set (COMMON_WARNING_Clang "-Wall -pedantic")
set (COMMON_WARNING_MSVC "")
string (JOIN " " COMMON_WARNING_MSVC "/W4" "/analyze"
# disabled warnings /wd
"/wd4090" # 'function': different 'const' qualifiers
"/wd4100" # 'argv': unreferenced formal parameter
"/wd4127" # conditional expression is constant
"/wd4133" # 'function': incompatible types - from 'pn_durability_t *' to 'uint32_t *'
"/wd4180" # qualifier applied to function type has no meaning; ignored
"/wd4189" # 'status': local variable is initialized but not referenced
"/wd4211" # nonstandard extension used: redefined extern to static
"/wd4232" # nonstandard extension used: 'incref': address of dllimport 'pn_void_incref' is not static, identity not guaranteed
"/wd4244" # '+=': conversion from 'ssize_t' to 'uint32_t', possible loss of data
"/wd4245" # '=': conversion from 'int' to 'pn_socket_t', signed/unsigned mismatch
"/wd4267" # '=': conversion from 'size_t' to 'uint32_t', possible loss of data
"/wd4305" # 'type cast': truncation from 'pn_string_t *' to 'bool'
"/wd4389" # '!=': signed/unsigned mismatch
"/wd4456" # declaration of 'type' hides previous local declaration
"/wd4458" # declaration of 'handler' hides class member
"/wd4459" # declaration of 'buf' hides global declaration
"/wd4505" # 'ssl_session_free': unreferenced function with internal linkage has been removed
"/wd4701" # potentially uninitialized local variable 'evalue' used
"/wd4702" # unreachable code
"/wd4703" # potentially uninitialized local pointer variable 'port' used
"/wd4706" # assignment within conditional expression
"/wd4800" # Implicit conversion from 'type' to bool. Possible information loss
"/wd4996" # 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead.
"/wd6001" # Using uninitialized memory '*a->addresses'.
"/wd6011" # Dereferencing NULL pointer 'buf'.
"/wd6031" # Return value ignored: 'InitializeCriticalSectionAndSpinCount'.
"/wd6101" # Returning uninitialized memory '*Mtu'. A successful path through the function does not set the named _Out_ parameter.
"/wd6217" # Implicit cast between semantically different integer types: testing HRESULT with 'not'.
"/wd6221" # Implicit cast between semantically different integer types: comparing HRESULT to an integer.
"/wd6230" # Implicit cast between semantically different integer types: using HRESULT in a Boolean context.
"/wd6244" # Local declaration of 'buf' hides previous declaration at line '33'
"/wd6246" # Local declaration of 'type' hides declaration of the same name in outer scope.
"/wd6308" # 'realloc' might return null pointer: assigning null pointer to 'a->addresses', which is passed as an argument to 'realloc', will cause the original memory block to be leaked.
"/wd6328" # Size mismatch: 'unsigned __int64' passed as _Param_(2) when 'int' is required in call to 'iocp_log'.
"/wd6336" # Arithmetic operator has precedence over question operator, use parentheses to clarify intent.
"/wd6340" # Mismatch on sign: 'unsigned char' passed as _Param_(5) when some signed type is required in call to 'pn_logger_logf'.
"/wd6385" # Reading invalid data from 'conn->rbuffers'.
"/wd6386" # Buffer overrun while writing to 'nargv': the writable size is '_Param_(1)*_Param_(2)' bytes, but '16' bytes might be written.
"/wd6387" # 'rbytes' could be '0': this does not adhere to the specification for the function 'memcpy'.
# warnings as error /we
"/we28251" # Inconsistent annotation for function: this instance has an error
"/we26819" # Unannotated fallthrough between switch labels
)

set (CC_WARNING_GNU "-Wno-unused-parameter -Wstrict-prototypes -Wvla -Wsign-compare -Wwrite-strings -Wimplicit-fallthrough=3")
set (CC_WARNING_Clang "-Wno-unused-parameter -Wstrict-prototypes -Wvla -Wsign-compare -Wwrite-strings -Wimplicit-fallthrough")
set (CC_WARNING_MSVC "/wd4244 /wd4267 /wd4800 /wd4996 /we26819")
set (CC_WARNING_MSVC "")

set (CXX_WARNING_GNU "")
set (CXX_WARNING_Clang "")
Expand Down
4 changes: 2 additions & 2 deletions c/src/core/connection_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void pn_connection_driver_verrorf(pn_connection_driver_t *d, const char *name, c
pn_condition_vformat(cond, name, fmt, ap);
}

void pn_connection_driver_errorf(pn_connection_driver_t *d, const char *name, const char *fmt, ...) {
void pn_connection_driver_errorf(pn_connection_driver_t *d, const char *name, PN_PRINTF_FORMAT const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
pn_connection_driver_verrorf(d, name, fmt, ap);
Expand All @@ -168,7 +168,7 @@ void pn_connection_driver_log(pn_connection_driver_t *d, const char *msg) {
pni_logger_log(&d->transport->logger, PN_SUBSYSTEM_IO, PN_LEVEL_TRACE, msg);
}

void pn_connection_driver_logf(pn_connection_driver_t *d, const char *fmt, ...) {
void pn_connection_driver_logf(pn_connection_driver_t *d, PN_PRINTF_FORMAT const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
pni_logger_vlogf(&d->transport->logger, PN_SUBSYSTEM_IO, PN_LEVEL_TRACE, fmt, ap);
Expand Down
2 changes: 1 addition & 1 deletion c/src/core/engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2215,7 +2215,7 @@ int pn_condition_vformat(pn_condition_t *condition, const char *name, const char
return err;
}

int pn_condition_format(pn_condition_t *condition, const char *name, const char *fmt, ...)
int pn_condition_format(pn_condition_t *condition, const char *name, PN_PRINTF_FORMAT const char *fmt, ...)
{
assert(condition);
va_list ap;
Expand Down
2 changes: 1 addition & 1 deletion c/src/core/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int pn_error_vformat(pn_error_t *error, int code, const char *fmt, va_list ap)
return pn_error_set(error, code, text);
}

int pn_error_format(pn_error_t *error, int code, const char *fmt, ...)
int pn_error_format(pn_error_t *error, int code, PN_PRINTF_FORMAT const char *fmt, ...)
{
assert(error);
va_list ap;
Expand Down
2 changes: 1 addition & 1 deletion c/src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void pni_vlogf_impl(const char *fmt, va_list ap) {
* complicated messages.) It is important that a disabled log statement results
* in nothing more than a call to pni_log_enabled().
*/
void pni_logf_impl(const char *fmt, ...) {
void pni_logf_impl(PN_PRINTF_FORMAT const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
pni_vlogf_impl(fmt, ap);
Expand Down
6 changes: 3 additions & 3 deletions c/src/core/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void pni_logger_log_raw(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_lo
}
}

void pni_logger_log_msg_inspect(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, void* object, const char *fmt, ...) {
void pni_logger_log_msg_inspect(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, void* object, PN_PRINTF_FORMAT const char *fmt, ...) {
va_list ap;
char buf[1024];
pn_fixed_string_t out = pn_fixed_string(buf, sizeof(buf));
Expand All @@ -236,7 +236,7 @@ void pni_logger_log_msg_inspect(pn_logger_t *logger, pn_log_subsystem_t subsyste
pni_logger_log(logger, subsystem, severity, buf);
}

void pni_logger_log_msg_frame(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, pn_bytes_t frame, const char *fmt, ...) {
void pni_logger_log_msg_frame(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, pn_bytes_t frame, PN_PRINTF_FORMAT const char *fmt, ...) {
va_list ap;
char buf[1024];
pn_fixed_string_t output = pn_fixed_string(buf, sizeof(buf));
Expand Down Expand Up @@ -283,7 +283,7 @@ void pni_logger_vlogf(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_
pni_logger_log(logger, subsystem, severity, buf);
}

void pn_logger_logf(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, const char *fmt, ...)
void pn_logger_logf(pn_logger_t *logger, pn_log_subsystem_t subsystem, pn_log_level_t severity, PN_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;

Expand Down
4 changes: 2 additions & 2 deletions c/src/core/object/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void pn_string_clear(pn_string_t *string)
pn_string_set(string, NULL);
}

int pn_string_format(pn_string_t *string, const char *format, ...)
int pn_string_format(pn_string_t *string, PN_PRINTF_FORMAT const char *format, ...)
{
va_list ap;

Expand All @@ -220,7 +220,7 @@ int pn_string_vformat(pn_string_t *string, const char *format, va_list ap)
return pn_string_vaddf(string, format, ap);
}

int pn_string_addf(pn_string_t *string, const char *format, ...)
int pn_string_addf(pn_string_t *string, PN_PRINTF_FORMAT const char *format, ...)
{
va_list ap;

Expand Down
4 changes: 2 additions & 2 deletions c/src/core/transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ static void pni_close_tail(pn_transport_t *transport)
}
}

int pn_do_error(pn_transport_t *transport, const char *condition, const char *fmt, ...)
int pn_do_error(pn_transport_t *transport, const char *condition, PN_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand Down Expand Up @@ -2840,7 +2840,7 @@ void pn_transport_vlogf(pn_transport_t *transport, const char *fmt, va_list ap)
pni_logger_vlogf(logger, PN_SUBSYSTEM_ALL, PN_LEVEL_TRACE, fmt, ap);
}

void pn_transport_logf(pn_transport_t *transport, const char *fmt, ...)
void pn_transport_logf(pn_transport_t *transport, PN_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;

Expand Down
2 changes: 1 addition & 1 deletion c/src/sasl/sasl.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static const char pni_excluded_mechs[] = "GSSAPI GSS-SPNEGO GS2-KRB5 GS2-IAKERB"
//-----------------------------------------------------------------------------
// pnx_sasl: API for SASL implementations to use

void pnx_sasl_logf(pn_transport_t *logger, pn_log_level_t level, const char *fmt, ...)
void pnx_sasl_logf(pn_transport_t *logger, pn_log_level_t level, PN_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand Down
9 changes: 6 additions & 3 deletions c/src/ssl/schannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ static void ssl_vlog(pn_transport_t *transport, pn_log_level_t sev, const char *
}
}

static void ssl_log(pn_transport_t *transport, pn_log_level_t sev, const char *fmt, ...)
PN_PRINTF_FORMAT_ATTR(3, 4)
static void ssl_log(pn_transport_t *transport, pn_log_level_t sev, PN_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand All @@ -383,15 +384,17 @@ static void ssl_log(pn_transport_t *transport, pn_log_level_t sev, const char *f
}

// @todo: used to avoid littering the code with calls to printf...
static void ssl_log_error(const char *fmt, ...)
PN_PRINTF_FORMAT_ATTR(1, 2)
static void ssl_log_error(PN_PRINTF_FORMAT const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
ssl_vlog(NULL, PN_LEVEL_ERROR, fmt, ap);
va_end(ap);
}

static void ssl_log_error_status(HRESULT status, const char *fmt, ...)
PN_PRINTF_FORMAT_ATTR(2, 3)
static void ssl_log_error_status(HRESULT status, PN_PRINTF_FORMAT const char *fmt, ...)
{
char buf[512];
va_list ap;
Expand Down
2 changes: 1 addition & 1 deletion c/tools/msgr-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void enable_logging(void)
dolog = 1;
}

void LOG( const char *fmt, ... )
void LOG( PN_PRINTF_FORMAT const char *fmt, ... )
{
if (dolog) {
va_list ap;
Expand Down