make sure buf is NULL terminated refs #2