[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <51E7904C.8060100@asianux.com>
Date: Thu, 18 Jul 2013 14:50:52 +0800
From: Chen Gang <gang.chen@...anux.com>
To: George Spelvin <linux@...izon.com>
CC: andrei.emeltchenko@...el.com, andriy.shevchenko@...ux.intel.com,
jkosina@...e.cz, akpm@...ux-foundation.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] lib/vsprintf.c: fix the incorrect return value of vsnprintf()
On 07/18/2013 02:42 PM, George Spelvin wrote:
>> When "str >= end", necessary to reset 'str' to "end - 1", or the return
>> > value will be larger than the real one, the callers which depend on the
>> > return value, may cause memory overflow.
> NAK. This is the documented (by both the function itself and the
> ANSI/ISO C standard) and desired return value: the number of bytes that
> *would* have been in the output string if the buffer were large enough.
> In particular, it is common to do:
>
> size = vsnprintf(NULL, 0, fmt, args) + 1;
> p = malloc(size, GFP_KERNEL);
> vsnprintf(p, size, fmt, args);
>
OK, it is my fault, thank you very much.
> You want vscnprintf. If you have a caller that needs the *actual* number of
> bytes written, use that.
>
>
Yeah, my another patch need use vscnprintf() instead of vsnprintf(),
thanks again.
Thanks.
--
Chen Gang
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists