On Feb 5, 2008 11:08 AM, Andy Lester <[EMAIL PROTECTED]> wrote:
> Constructions like this give me the willies:
>
>    char * const buf = (char *)mem_sys_allocate(16);
>    sprintf(buf, "%d", type);
>
i saw this code the other day, and thought, "gee, malloc's just gonna
grab 64 anyway. that's silly."

> Yes, I know that 16 characters is more than enough, but I still don't
> like it.  I'd prefer it if we were using instead
>
>    snprintf(buf, 16, "%d", type);
>
> I suspect there's a teeny performance hit since snprintf() has to
> check how far it's gone, but I can't imagine it's big enough to offset
> the safety.
>
i like it.
~jerry

Reply via email to