added check for malloc() failure.
silence compiler warning.
Added tests for encode small integers.
Added null pointer check
Fixed decode tail operator for string