[patch iwhd 2/3] do not leak "pending"

Jim Meyering jim at meyering.net
Fri Jul 8 08:55:09 UTC 2011


Pete Zaitcev wrote:

> On Fri, 08 Jul 2011 07:45:56 +0200
> Jim Meyering <jim at meyering.net> wrote:
>
>>   - when a simple tool can do the job just as well, why use a much
>>       larger, more powerful one?
>
> Mostly for the code uniformity with other sites where ami_id_buf
> is filled. I was even thinking about going snprintf wholesale,
> although obviously short tags always fit.

Please reconsider.
IMHO, if you're formatting things and heap allocation is ok (i.e.,
the potential for failure is acceptable), then it's ok to use
asprintf or xasprintf.

Otherwise, it's a lot easier to make the code maintainable
by mortals if you avoid fixed-sized buffers and pointer arithmetic.
An added advantage of using an allocating interface like asprintf
is that you needn't impose arbitrary limits.  Arbitrary limits
aren't terribly bad in and of themselves, but handling the cases
in which those limits are exceeded adds undesirable complexity
that is rarely tested and hence error-prone.

Oh, and in case you still think sn?print are worth using when not
absolutely necessary, please read this, and be amazed that glibc's
implementation actually allocates memory:

    http://thread.gmane.org/gmane.comp.lib.gnulib.bugs/23838


More information about the iwhd-devel mailing list