Avoid calling calloc with 0 length data.

CERT MEM04-C suggests that zero length allocations behaviour might be
surprising so it should be avoided. This adds a check to ensure a zero
length allocation will be avoided. Additionally it returns errors to
the caller rather than warning directly (in some error paths)
Doxygen cleanups
Doxygen cleanups and documentation additions