Messages in this thread | | | Date | Thu, 18 Jul 2013 14:50:52 +0800 | From | Chen Gang <> | 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
| |