public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chen Gang <gang.chen@asianux.com>
To: George Spelvin <linux@horizon.com>
Cc: andrei.emeltchenko@intel.com, andriy.shevchenko@linux.intel.com,
	jkosina@suse.cz, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/vsprintf.c: fix the incorrect return value of vsnprintf()
Date: Thu, 18 Jul 2013 14:50:52 +0800	[thread overview]
Message-ID: <51E7904C.8060100@asianux.com> (raw)
In-Reply-To: <20130718064238.25532.qmail@science.horizon.com>

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

  reply	other threads:[~2013-07-18  6:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-18  6:28 [PATCH] lib/vsprintf.c: fix the incorrect return value of vsnprintf() Chen Gang
2013-07-18  6:42 ` George Spelvin
2013-07-18  6:50   ` Chen Gang [this message]
2013-07-18  6:49 ` Al Viro
2013-07-18  6:52   ` Chen Gang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51E7904C.8060100@asianux.com \
    --to=gang.chen@asianux.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrei.emeltchenko@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@horizon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox