mirror of
https://github.com/curl/curl.git
synced 2026-08-25 16:03:40 +03:00
build: drop global suppression of -Wformat-nonliteral, fix fallouts
Extend two existing local suppressions to GCC, and add another
GCC-specific one as a replacement.
Before this patch suppressing this warning was odd with clang, because
after this option, `-Wformat=2` is used, which re-enables it.
Also:
- mprintf: minimize scope of a warning suppression.
- tests/server: suppress this warning for a system `vsnprintf()` call
where it could trigger in C89 builds or with
`CFLAGS=-DCURL_NO_FMT_CHECKS` set. Seen with Apple clang 17:
```
curl/tests/server/util.c:114:37: warning: format string is not a string literal [-Wformat-nonliteral]
114 | vsnprintf(buffer, sizeof(buffer), msg, ap);
| ^~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:124:69: note: expanded from macro 'vsnprintf'
124 | #define vsnprintf(str, len, ...) __vsnprintf_chk_func (str, len, 0, __VA_ARGS__)
| ^~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/secure/_stdio.h:81:65: note: expanded from macro '__vsnprintf_chk_func'
81 | __builtin___vsnprintf_chk (str, len, flag, __darwin_obsz(str), format, ap)
| ^~~~~~
```
Ref: #20363
Closes #20366
This commit is contained in:
parent
c1ef1876ac
commit
f07a98ae11
6 changed files with 27 additions and 19 deletions
|
|
@ -673,16 +673,19 @@ static bool out_double(void *userp,
|
|||
|
||||
*fptr = 0; /* and a final null-termination */
|
||||
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
/* NOTE NOTE NOTE!! Not all sprintf implementations return number of
|
||||
output characters */
|
||||
#ifdef HAVE_SNPRINTF
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
#endif
|
||||
/* !checksrc! disable LONGLINE */
|
||||
/* NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling) */
|
||||
(snprintf)(work, BUFFSIZE, formatbuf, dnum);
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
/* Old versions of the Windows CRT do not terminate the snprintf output
|
||||
buffer if it reaches the max size so we do that here. */
|
||||
|
|
@ -691,9 +694,6 @@ static bool out_double(void *userp,
|
|||
#else
|
||||
/* float and double outputs do not work without snprintf support */
|
||||
work[0] = 0;
|
||||
#endif
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
DEBUGASSERT(strlen(work) < BUFFSIZE);
|
||||
while(*work) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue