Fix a possible bug with variable length character encoding