Unix Technical Forum

Re: more improvements for mg

This is a discussion on Re: more improvements for mg within the mailing.openbsd.tech forums, part of the OpenBSD category; --> On 2005-05-16 at 17:59:04 Todd C. Miller wrote: >> ret = snprintf(foo, sizeof(foo), "%s", input); >> if (ret < ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 07:50 AM
Dimitry Andric
 
Posts: n/a
Default Re: more improvements for mg

On 2005-05-16 at 17:59:04 Todd C. Miller wrote:

>> ret = snprintf(foo, sizeof(foo), "%s", input);
>> if (ret < 0 || (size_t)ret >= sizeof(foo))

> While this does look OK I really don't see the need for the cast
> to size_t.


So you'd rather have "ret >= (int)sizeof(foo)" ? Since the compiler
will probably complain if you don't apply any casts.


> In practice sizeof(foo) will not be > INT_MAX unless you are
> creating 2GB data structures on the stack and the stack is not big
> enough to hold such a data structure anyway.


If you put it on the stack, certainly, but not if you got the storage
somewhere else. To me, snprintf's prototype seems inconsistent
anyway; it would be more logical if it returned an ssize_t. Although
this still wouldn't save you from the signed/unsigned nastiness...

[demime 1.01d removed an attachment of type application/pgp-signature]

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:43 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com