Adding null checks to functions that encode strings and bytes