Re: [PATCH] lib: fix scnprintf() if @size is == 0
From: Changli Gao
Date: Tue Aug 24 2010 - 20:10:47 EST
On Wed, Aug 25, 2010 at 8:03 AM, Joe Perches <joe@xxxxxxxxxxx> wrote:
>
> Isn't simpler to check size at the beginning of the function?
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 7af9d84..779236f 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -1505,6 +1505,9 @@ int scnprintf(char *buf, size_t size, const char *fmt, ...)
> va_list args;
> int i;
>
> + if (!size)
> + return 0;
> +
It is a rare case, so don't slow down the normal users.
> va_start(args, fmt);
> i = vsnprintf(buf, size, fmt, args);
> va_end(args);
>
>
>
--
Regards,
Changli Gao(xiaosuo@xxxxxxxxx)
--
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/