build: delete/replace clang warning pragmas

- delete redundant warning suppressions for `-Wformat-nonliteral`.
  This now relies on `CURL_PRINTF()` and it's theoratically possible
  that this macro isn't active but the warning is. We're ignoring this
  as a corner-case here.

- replace two pragmas with code changes to avoid the warnings.

Follow-up to aee4ebe591 #12803
Follow-up to 0923012758 #12540
Follow-up to 3829759bd0 #12489

Reviewed-by: Daniel Stenberg
Closes #12812
This commit is contained in:
Viktor Szakats 2024-01-27 17:40:38 +00:00
parent ecb5d6bee9
commit 5b286c2508
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
9 changed files with 5 additions and 87 deletions

View file

@ -113,14 +113,7 @@ CURLcode easysrc_addf(struct slist_wc **plist, const char *fmt, ...)
char *bufp;
va_list ap;
va_start(ap, fmt);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
bufp = curlx_mvaprintf(fmt, ap);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
va_end(ap);
if(!bufp) {
ret = CURLE_OUT_OF_MEMORY;

View file

@ -53,14 +53,7 @@ static void voutf(struct GlobalConfig *config,
char *ptr;
char *print_buffer;
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
print_buffer = curlx_mvaprintf(fmt, ap);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
if(!print_buffer)
return;
len = strlen(print_buffer);

View file

@ -240,22 +240,11 @@ static char *c_escape(const char *str, curl_off_t len)
if(p && *p)
result = curlx_dyn_addn(&escaped, to + 2 * (p - from), 2);
else {
const char *format = "\\x%02x";
if(len > 1 && ISXDIGIT(s[1])) {
/* Octal escape to avoid >2 digit hex. */
format = "\\%03o";
}
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
result = curlx_dyn_addf(&escaped, format,
result = curlx_dyn_addf(&escaped,
/* Octal escape to avoid >2 digit hex. */
(len > 1 && ISXDIGIT(s[1])) ?
"\\%03o" : "\\x%02x",
(unsigned int) *(unsigned char *) s);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
}
}