Make sure that buffer is null terminated