[warnings] fix format nonliteral

add pragma to suppress format nonliteral warnings where appropriate
This commit is contained in:
akallabeth
2024-09-12 00:21:27 +02:00
parent 8a990644c0
commit cc6850bf21
8 changed files with 26 additions and 0 deletions

View File

@@ -737,12 +737,15 @@ static BOOL isAutomountLocation(const char* path)
const char* location = automountLocations[x];
size_t length = 0;
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
if (strstr(location, "%lu"))
(void)snprintf(buffer, sizeof(buffer), location, (unsigned long)uid);
else if (strstr(location, "%s"))
(void)snprintf(buffer, sizeof(buffer), location, uname);
else
(void)snprintf(buffer, sizeof(buffer), "%s", location);
WINPR_PRAGMA_DIAG_POP
length = strnlen(buffer, sizeof(buffer));

View File

@@ -456,7 +456,10 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap)
va_list copy;
va_copy(copy, ap);
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
size = vsnprintf(res.data(), res.size(), fmt, copy);
WINPR_PRAGMA_DIAG_POP
va_end(copy);
} while ((size > 0) && (static_cast<size_t>(size) > res.size()));

View File

@@ -455,7 +455,10 @@ std::string SDLConnectionDialog::print(const char* fmt, va_list ap)
va_list copy;
va_copy(copy, ap);
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
size = vsnprintf(res.data(), res.size(), fmt, copy);
WINPR_PRAGMA_DIAG_POP
va_end(copy);
} while ((size > 0) && (static_cast<size_t>(size) > res.size()));

View File

@@ -430,6 +430,8 @@ static BOOL check_primary_order_supported(wLog* log, rdpSettings* settings, UINT
return check_order_activated(log, settings, orderName, condition, extendedMessage);
}
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
static const char* primary_order_string(UINT32 orderType)
{
const char* orders[] = { "[0x%02" PRIx8 "] DstBlt",
@@ -509,6 +511,7 @@ static const char* altsec_order_string(BYTE orderType)
(void)sprintf_s(buffer, ARRAYSIZE(buffer), fmt, orderType);
return buffer;
}
WINPR_PRAGMA_DIAG_POP
static INLINE BOOL update_read_coord(wStream* s, INT32* coord, BOOL delta)
{

View File

@@ -1322,6 +1322,8 @@ static const struct
const char skey[6];
} options = { "--pcap=", "--fast", "--port=", "--local-only", "--cert=", "--key=" };
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
WINPR_ATTR_FORMAT_ARG(2, 0)
static void print_entry(FILE* fp, WINPR_FORMAT_ARG const char* fmt, const char* what, size_t size)
{
@@ -1329,6 +1331,7 @@ static void print_entry(FILE* fp, WINPR_FORMAT_ARG const char* fmt, const char*
strncpy(buffer, what, MIN(size, sizeof(buffer) - 1));
(void)fprintf(fp, fmt, buffer);
}
WINPR_PRAGMA_DIAG_POP
static WINPR_NORETURN(void usage(const char* app, const char* invalid))
{

View File

@@ -41,6 +41,8 @@
_Pragma("clang diagnostic ignored \"-Wunused-const-variable\"")
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \
_Pragma("clang diagnostic ignored \"-Wformat-security\"")
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \
_Pragma("clang diagnostic ignored \"-Wformat-nonliteral\"")
#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC /* not supported \
_Pragma("clang diagnostic ignored \"-Wmismatched-dealloc\"") */
#define WINPR_PRAGMA_DIAG_POP _Pragma("clang diagnostic pop")
@@ -65,6 +67,8 @@
_Pragma("GCC diagnostic ignored \"-Wunused-const-variable\"")
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY \
_Pragma("GCC diagnostic ignored \"-Wformat-security\"")
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL \
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
#if __GNUC__ >= 11
#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC \
_Pragma("GCC diagnostic ignored \"-Wmismatched-dealloc\"")
@@ -84,6 +88,7 @@
#define WINPR_PRAGMA_DIAG_IGNORED_ATOMIC_SEQ_CST
#define WINPR_PRAGMA_DIAG_IGNORED_UNUSED_CONST_VAR
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_SECURITY
#define WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
#define WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
#define WINPR_PRAGMA_DIAG_POP
#define WINPR_PRAGMA_UNROLL_LOOP

View File

@@ -194,7 +194,10 @@ static BOOL replace_format_string(const char* FormatString, struct format_option
if (replace && (replacelen > 0))
{
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
const int rc = _snprintf(&format[index], formatlen - index, replace, arg);
WINPR_PRAGMA_DIAG_POP
if (rc < 0)
return FALSE;
if (!check_and_log_format_size(format, formatlen, index, rc))

View File

@@ -373,9 +373,12 @@ BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, size_t line, const
{
char formattedLogMessage[WLOG_MAX_STRING_SIZE] = { 0 };
WINPR_PRAGMA_DIAG_PUSH
WINPR_PRAGMA_DIAG_IGNORED_FORMAT_NONLITERAL
if (vsnprintf(formattedLogMessage, WLOG_MAX_STRING_SIZE - 1, message.FormatString,
args) < 0)
return FALSE;
WINPR_PRAGMA_DIAG_POP
message.TextString = formattedLogMessage;
status = WLog_Write(log, &message);