Skip to content

Commit

Permalink
coredump: add __printf attribute to cn_*printf functions
Browse files Browse the repository at this point in the history
This allows detecting improper format string at build time, like:

  fs/coredump.c:225:5: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int' [-Wformat=]
       err = cn_printf(cn, "%ld", cprm->siginfo->si_signo);
       ^

As si_signo is always an int, the format should be %d here.

Signed-off-by: Nicolas Iooss <[email protected]>
Acked-by: "Eric W. Biederman" <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
fishilico authored and torvalds committed Jun 26, 2015
1 parent 5202efe commit b4176b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions fs/coredump.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ static int expand_corename(struct core_name *cn, int size)
return 0;
}

static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
static __printf(2, 0) int cn_vprintf(struct core_name *cn, const char *fmt,
va_list arg)
{
int free, need;
va_list arg_copy;
Expand All @@ -93,7 +94,7 @@ static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
return -ENOMEM;
}

static int cn_printf(struct core_name *cn, const char *fmt, ...)
static __printf(2, 3) int cn_printf(struct core_name *cn, const char *fmt, ...)
{
va_list arg;
int ret;
Expand All @@ -105,7 +106,8 @@ static int cn_printf(struct core_name *cn, const char *fmt, ...)
return ret;
}

static int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
static __printf(2, 3)
int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
{
int cur = cn->used;
va_list arg;
Expand Down Expand Up @@ -225,7 +227,8 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
break;
/* signal that caused the coredump */
case 's':
err = cn_printf(cn, "%ld", cprm->siginfo->si_signo);
err = cn_printf(cn, "%d",
cprm->siginfo->si_signo);
break;
/* UNIX time of coredump */
case 't': {
Expand Down

0 comments on commit b4176b7

Please sign in to comment.