All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Henrik Nordstrom <hno@marasystems.com>
Cc: johnpol@2ka.mipt.ru, Harald Welte <laforge@netfilter.org>,
	netfilter-devel@lists.netfilter.org
Subject: Re: [2/2] osf: fixed /proc reading bug
Date: Sun, 22 Aug 2004 02:15:02 +0200	[thread overview]
Message-ID: <4127E586.5000707@trash.net> (raw)
In-Reply-To: <Pine.LNX.4.61.0408220142220.21373@filer.marasystems.com>

Henrik Nordstrom wrote:

> On Sun, 22 Aug 2004, Patrick McHardy wrote:
>
>>               log("%s [%s]", f->genre, f->details);
>>
>> -               count += sprintf(buf+count, "%s - %s[%s] : %s",
>> +               err = snprintf(buf+count, __count-count, "%s - %s[%s] 
>> : %s",
>>                                       f->genre, f->version,
>>                                       f->subtype, f->details);
>> -
>> +               if (err < 0)
>
>
> This should read something like follows I think:
>
>           if (err < 0 || err > __count-count)
>
>> +                       break;
>> +               else
>> +                       count += err;
>>               if (f->opt_num)
>>               {
>>                       loga(" OPT: ");
>

Yes, but the check for < 0 is not needed and it should read >= __count - 
count
to avoid useless zero-byte snprintfs. Evgeniy, can you please send a new 
patch ?

>>
>> snprintf returns the number of characters written if n <= limit, 
>> otherwise
>> the number of characters that would have been generated for the given 
>> input,
>> but never < 0. You can also use vscnprintf to get the real number of 
>> bytes
>> written.
>
>
> There may still be systems around with old snprintf implementations 
> returning -1 on overflow unless this is kernel code.

It is. The *nprintf behaviour really is surprising (and annoying for 
chaining
multiple snprintfs), given the behaviour of the *printf functions. OTOH, 
there
is no other way to distinguish "n bytes written" with "truncated to n bytes"
and returning -1 is even worse.

Regards
Patrick

  reply	other threads:[~2004-08-22  0:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-21 21:03 [2/2] osf: fixed /proc reading bug Evgeniy Polyakov
2004-08-21 22:30 ` Patrick McHardy
2004-08-21 23:48   ` Henrik Nordstrom
2004-08-22  0:15     ` Patrick McHardy [this message]
2004-08-23  8:57       ` Evgeniy Polyakov
2004-08-23  9:55         ` Patrick McHardy
2004-08-23 10:30           ` Evgeniy Polyakov
2004-08-23 10:38             ` Henrik Nordstrom
2004-08-23 10:39             ` Evgeniy Polyakov
2004-08-23 11:35               ` Evgeniy Polyakov
2004-08-23 18:33                 ` Patrick McHardy

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=4127E586.5000707@trash.net \
    --to=kaber@trash.net \
    --cc=hno@marasystems.com \
    --cc=johnpol@2ka.mipt.ru \
    --cc=laforge@netfilter.org \
    --cc=netfilter-devel@lists.netfilter.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.