Fix another incorrect use of max_bytes_per_codepoint and adjust loop termination condition