[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: more improvements for mg
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: Re: more improvements for mg
- From: Alexandre Ratchov <alex-contact_(_at_)_caoua_(_dot_)_org>
- Date: Mon, 16 May 2005 17:17:48 +0200
On Mon, May 16, 2005 at 01:40:40PM +0159, Han Boetes wrote:
> Han Boetes wrote:
> > Theo de Raadt wrote:
> > > snprintf does not return size_t
> > sizeof returns size_t
imho, there is no elegant solution since size_t is unsigned
and snprintf(3) returns a signed int. snprintf(3) is just unable
to handle strings longer than INT_MAX (2^31 - 1 on 32bit arch).
However, once we are sure that ret >= 0, it seems to me reasonable
to compare 'ret' to sizeof(foo), example:
ret = snprintf(foo, sizeof(foo), "%s", input);
if (ret < 0 || (size_t)ret >= sizeof(foo))
-1 means that snprintf failed and negative number of chars is meaningless.
This works if sizeof(foo) > INT_MAX because res is converted to size_t.
Have i missed something?
Visit your host, monkey.org