Fix potential issue in the charset encoder