Little conveniences
Ken Raeburn
raeburn at MIT.EDU
Thu Oct 1 14:39:24 EDT 2009
On Oct 1, 2009, at 13:29, Paul Moore wrote:
> or even
>
> static inline void k5alloc(size_t size)
> {
> return calloc(size, 1);
> }
>
> since the results is either good or ENOMEM, there not a lot of point
> in
> returning the failure reason
I assume part of the idea was to avoid doing the ENOMEM setting
explicitly at every call site.
I'll note, though, that a NULL return value may not mean failure, if
the requested size was zero. Open-coding that additional check, at
every call site that hasn't been checked to ensure that zero couldn't
be passed in, would also be annoying. If zero-sized allocations are
allowed and aren't adjusted to allocate at least one byte, then the
caller needs to check the error code and not the pointer, in the
general case; certainly there will be a number of calls where zero
can't be passed.
Ken
More information about the krbdev
mailing list