Fixed reallocation error.  Tighter types (const).

Expansion of the buffer was not gauranteed to expand in a way such that the
unused bytes were nul, resulting in non-null terminated string buffers.

Added the 'const' modifier where appropriate to function parameters.