fix NULL deref in to_string