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 < ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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] |