[OCaml] Code simplification using string allocation functions
Using the cstr_to_string function that allocates and initializes an
OCaml string value enables simplifications in several cases. This
change also has the effect of avoiding calling memcpy on NULL
pointers even if only 0 bytes are to be copied.
Differential Revision: https://reviews.llvm.org/D99474