Re: [PATCH v2] modpost: fix asprintf warnings

From: AmÃrico Wang
Date: Thu Dec 10 2009 - 01:53:00 EST


On Thu, Dec 10, 2009 at 9:16 AM, Mike Frysinger <vapier@xxxxxxxxxx> wrote:
> On compilers with security warnings enabled by default, we get:
>
> scripts/mod/modpost.c: In function 'get_markers':
> scripts/mod/modpost.c:1562: warning: ignoring return value of 'asprintf',
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â declared with attribute warn_unused_result
> scripts/mod/modpost.c: In function 'add_marker':
> scripts/mod/modpost.c:1982: warning: ignoring return value of 'asprintf',
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â declared with attribute warn_unused_result
>
> So check the return value and abort on errors.
>
> Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>


Acked-by: WANG Cong <xiyou.wangcong@xxxxxxxxx>

> ---
> v2
> Â Â Â Â- add missing newline pointed out by AmÃrico Wang
>
> Âscripts/mod/modpost.c | Â Â6 ++++--
> Â1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 801a16a..6608ebd 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1559,7 +1559,8 @@ static void get_markers(struct elf_info *info, struct module *mod)
> Â Â Â Â Â Â Â Â Â Â Â Âconst char *name = strings + sym->st_value;
> Â Â Â Â Â Â Â Â Â Â Â Âconst char *fmt = strchr(name, '\0') + 1;
> Â Â Â Â Â Â Â Â Â Â Â Âchar *line = NULL;
> - Â Â Â Â Â Â Â Â Â Â Â asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
> + Â Â Â Â Â Â Â Â Â Â Â if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â fatal("asprintf() with %s failed\n", name);
> Â Â Â Â Â Â Â Â Â Â Â ÂNOFAIL(line);
> Â Â Â Â Â Â Â Â Â Â Â Âmod->markers[n++] = line;
> Â Â Â Â Â Â Â Â}
> @@ -1979,7 +1980,8 @@ static void write_dump(const char *fname)
> Âstatic void add_marker(struct module *mod, const char *name, const char *fmt)
> Â{
> Â Â Â Âchar *line = NULL;
> - Â Â Â asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt);
> + Â Â Â if (asprintf(&line, "%s\t%s\t%s\n", name, mod->name, fmt) == -1)
> + Â Â Â Â Â Â Â fatal("asprintf() with %s failed\n", name);
> Â Â Â ÂNOFAIL(line);
>
> Â Â Â Âmod->markers = NOFAIL(realloc(mod->markers, ((mod->nmarkers + 1) *
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/