Fix buffer overflow in UTF-16 encoding.