forked from Mirror/frr
*: no-warn pragmas for non-const format strings
We do use non-constant/literal format strings in a few places for more or less valid reasons; put `ignored "-Wformat-nonliteral"` around those so we can have the warning enabled for everywhere else. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
0f9de11a11
commit
c84e518709
|
@ -117,9 +117,13 @@ static FILE *bgp_dump_open_file(struct bgp_dump *bgp_dump)
|
|||
if (bgp_dump->filename[0] != DIRECTORY_SEP) {
|
||||
snprintf(fullpath, sizeof(fullpath), "%s/%s", vty_get_cwd(),
|
||||
bgp_dump->filename);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* user supplied date/time format string */
|
||||
ret = strftime(realpath, MAXPATHLEN, fullpath, &tm);
|
||||
} else
|
||||
ret = strftime(realpath, MAXPATHLEN, bgp_dump->filename, &tm);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
if (ret == 0) {
|
||||
flog_warn(EC_BGP_DUMP, "%s: strftime error", __func__);
|
||||
|
|
|
@ -77,7 +77,11 @@ log_warn(const char *emsg, ...)
|
|||
vlog(LOG_ERR, emsg, ap);
|
||||
logit(LOG_ERR, "%s", strerror(errno));
|
||||
} else {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* format extended above */
|
||||
vlog(LOG_ERR, nfmt, ap);
|
||||
#pragma GCC diagnostic pop
|
||||
free(nfmt);
|
||||
}
|
||||
va_end(ap);
|
||||
|
|
|
@ -293,5 +293,9 @@ static ssize_t printfrr_va(struct fbuf *buf, struct printfrr_eargs *ea,
|
|||
* when allocating a larger buffer in asnprintfrr()
|
||||
*/
|
||||
va_copy(ap, *vaf->va);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* can't format check this */
|
||||
return vbprintfrr(buf, vaf->fmt, ap);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
|
|
|
@ -504,14 +504,20 @@ reswitch: switch (ch) {
|
|||
fmt[4] = ch;
|
||||
fmt[5] = '\0';
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
snprintf(buf, sizeof(buf), fmt, prec, arg);
|
||||
#pragma GCC diagnostic pop
|
||||
} else {
|
||||
double arg = GETARG(double);
|
||||
char fmt[5] = "%.*";
|
||||
fmt[3] = ch;
|
||||
fmt[4] = '\0';
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
snprintf(buf, sizeof(buf), fmt, prec, arg);
|
||||
#pragma GCC diagnostic pop
|
||||
}
|
||||
cp = buf;
|
||||
/* for proper padding */
|
||||
|
|
14
lib/vty.c
14
lib/vty.c
|
@ -343,6 +343,15 @@ void vty_hello(struct vty *vty)
|
|||
vty_out(vty, "%s", host.motd);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* prompt formatting has a %s in the cmd_node prompt string.
|
||||
*
|
||||
* Also for some reason GCC emits the warning on the end of the function
|
||||
* (optimization maybe?) rather than on the vty_out line, so this pragma
|
||||
* wraps the entire function rather than just the vty_out line.
|
||||
*/
|
||||
|
||||
/* Put out prompt and wait input from user. */
|
||||
static void vty_prompt(struct vty *vty)
|
||||
{
|
||||
|
@ -350,6 +359,7 @@ static void vty_prompt(struct vty *vty)
|
|||
vty_out(vty, cmd_prompt(vty->node), cmd_hostname_get());
|
||||
}
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* Send WILL TELOPT_ECHO to remote server. */
|
||||
static void vty_will_echo(struct vty *vty)
|
||||
|
@ -464,8 +474,12 @@ static int vty_command(struct vty *vty, char *buf)
|
|||
vty->address);
|
||||
|
||||
/* format the prompt */
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* prompt formatting has a %s in the cmd_node prompt string */
|
||||
snprintf(prompt_str, sizeof(prompt_str), cmd_prompt(vty->node),
|
||||
vty_str);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/* now log the command */
|
||||
zlog_notice("%s%s", prompt_str, buf);
|
||||
|
|
|
@ -339,8 +339,12 @@ yang_translate_xpath(const struct yang_translator *translator, int dir,
|
|||
if (!mapping)
|
||||
return YANG_TRANSLATE_NOTFOUND;
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* processing format strings from mapping node... */
|
||||
n = sscanf(xpath, mapping->xpath_from_fmt, keys[0], keys[1], keys[2],
|
||||
keys[3]);
|
||||
#pragma GCC diagnostic pop
|
||||
if (n < 0) {
|
||||
flog_warn(EC_LIB_YANG_TRANSLATION_ERROR,
|
||||
"%s: sscanf() failed: %s", __func__,
|
||||
|
@ -348,8 +352,12 @@ yang_translate_xpath(const struct yang_translator *translator, int dir,
|
|||
return YANG_TRANSLATE_FAILURE;
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* processing format strings from mapping node... */
|
||||
snprintf(xpath, xpath_len, mapping->xpath_to_fmt, keys[0], keys[1],
|
||||
keys[2], keys[3]);
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
return YANG_TRANSLATE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -743,7 +743,11 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
|
|||
fb.outpos_i = 0;
|
||||
|
||||
va_copy(args, msg->args);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* format-string checking is done further up the chain */
|
||||
need += vbprintfrr(&fb, msg->fmt, args);
|
||||
#pragma GCC diagnostic pop
|
||||
va_end(args);
|
||||
|
||||
msg->textlen = need;
|
||||
|
@ -762,7 +766,11 @@ const char *zlog_msg_text(struct zlog_msg *msg, size_t *textlen)
|
|||
fb.outpos_i = 0;
|
||||
|
||||
va_copy(args, msg->args);
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* same as above */
|
||||
vbprintfrr(&fb, msg->fmt, args);
|
||||
#pragma GCC diagnostic pop
|
||||
va_end(args);
|
||||
|
||||
bputch(&fb, '\n');
|
||||
|
|
|
@ -2759,6 +2759,15 @@ static char *do_prepend(struct vty *vty, struct cmd_token **argv, int argc)
|
|||
return frrstr_join(argstr, argc + off, " ");
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* 'headline' is a format string with a %s for the daemon name
|
||||
*
|
||||
* Also for some reason GCC emits the warning on the end of the function
|
||||
* (optimization maybe?) rather than on the vty_out line, so this pragma
|
||||
* wraps the entire function rather than just the vty_out line.
|
||||
*/
|
||||
|
||||
static int show_per_daemon(struct vty *vty, struct cmd_token **argv, int argc,
|
||||
const char *headline)
|
||||
{
|
||||
|
@ -2777,6 +2786,7 @@ static int show_per_daemon(struct vty *vty, struct cmd_token **argv, int argc,
|
|||
|
||||
return ret;
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
static int show_one_daemon(struct vty *vty, struct cmd_token **argv, int argc,
|
||||
const char *name)
|
||||
|
@ -4353,7 +4363,11 @@ char *vtysh_prompt(void)
|
|||
{
|
||||
static char buf[512];
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* prompt formatting has a %s in the cmd_node prompt string. */
|
||||
snprintf(buf, sizeof(buf), cmd_prompt(vty->node), cmd_hostname_get());
|
||||
#pragma GCC diagnostic pop
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
|
|
@ -512,7 +512,11 @@ static int run_job(struct restart_info *restart, const char *cmdtype,
|
|||
restart->kills = 0;
|
||||
{
|
||||
char cmd[strlen(command) + strlen(restart->name) + 1];
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
||||
/* user supplied command string has a %s for the daemon name */
|
||||
snprintf(cmd, sizeof(cmd), command, restart->name);
|
||||
#pragma GCC diagnostic pop
|
||||
if ((restart->pid = run_background(cmd)) > 0) {
|
||||
thread_add_timer(master, restart_kill, restart,
|
||||
gs.restart_timeout, &restart->t_kill);
|
||||
|
|
Loading…
Reference in a new issue