From: chas williams - CONTRACTOR <chas@cmf.nrl.navy.mil>
To: Chen Gang <gang.chen@asianux.com>
Cc: David Miller <davem@davemloft.net>, netdev <netdev@vger.kernel.org>
Subject: Re: [Suggestion] net/atm : for sprintf, need check the total write length whether larger than a page.
Date: Wed, 5 Dec 2012 09:55:03 -0500 [thread overview]
Message-ID: <20121205095503.6d1c083d@thirdoffive.cmf.nrl.navy.mil> (raw)
In-Reply-To: <50BEE2BE.2030704@asianux.com>
On Wed, 05 Dec 2012 13:59:26 +0800
Chen Gang <gang.chen@asianux.com> wrote:
> 于 2012年12月05日 13:40, Chen Gang 写道:
> > 于 2012年12月05日 12:56, Chen Gang 写道:
> >>>>>>>> - pos += sprintf(pos, "\n");
> >>>>>>>> + count += scnprintf(buf + count, PAGE_SIZE - count, "\n");
> >>>> ..
> >>>>>> need we judge whether count >= PAGE_SIZE ?
> >>>>
> >>>> count will eventually make PAGE_SIZE - count reach 0 at which point,
> >>>> scnprintf() won't be able to write into the buffer.
> >> I also think so.
> >>
> >> I think, maybe it will be better to break the loop when we already
> >> know that "count >= PAGE_SIZE" (it can save waste looping, although it
> >> seems unlikly happen, for example, using unlikly(...) ).
it doesn't seem like optimizing for this corner case is a huge
concern. the list cannot be infinitely long.
> >>
> >> By the way:
> >> will it be better that always let "\n" at the end ?
> >> (if count == PAGE_SIZE in a loop, we can not let "\n" at the end).
> >
> > oh, sorry ! count will never >= PAGE_SIZE.
> >
> > I think let "PAGE_SIZE - 2" instead of "PAGE_SIZE" in the loop, so we
> > can make the room for the end of "\n".
> >
> >
> >
> sorry, "PAGE_SIZE - 1" is enough, not need "PAGE_SIZE - 2".
did you mean '\0' instead of '\n'? scnprintf() considers the trailing
'\0' when formatting.
next prev parent reply other threads:[~2012-12-05 14:55 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-21 4:29 [Suggestion] net/atm : for sprintf, need check the total write length whether larger than a page Chen Gang
2012-12-03 8:56 ` Chen Gang
2012-12-03 15:48 ` chas williams - CONTRACTOR
2012-12-05 1:28 ` Chen Gang
2012-12-04 3:46 ` Chas Williams (CONTRACTOR)
2012-12-05 1:26 ` Chen Gang
2012-12-05 3:57 ` Chas Williams (CONTRACTOR)
2012-12-05 4:56 ` Chen Gang
2012-12-05 5:40 ` Chen Gang
2012-12-05 5:59 ` Chen Gang
2012-12-05 14:55 ` chas williams - CONTRACTOR [this message]
2012-12-06 1:15 ` Chen Gang
2012-12-06 9:05 ` Chen Gang
2012-12-06 14:08 ` chas williams - CONTRACTOR
2012-12-07 1:07 ` Chen Gang
2012-12-10 1:39 ` 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=20121205095503.6d1c083d@thirdoffive.cmf.nrl.navy.mil \
--to=chas@cmf.nrl.navy.mil \
--cc=davem@davemloft.net \
--cc=gang.chen@asianux.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).