lkml.org 
[lkml]   [2010]   [Aug]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] lib: fix scnprintf() if @size is == 0
On Wed, Aug 25, 2010 at 8:03 AM, Joe Perches <joe@perches.com> 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@gmail.com)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2010-08-25 02:13    [W:0.954 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site