@@ -149,10 +149,10 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter)
149
149
filter -> status = 1 ;
150
150
} else {
151
151
int n = (filter -> cache << 8 ) | (c & 0xFF );
152
+ filter -> cache = filter -> status = 0 ;
152
153
if (n == 0xFFFE ) {
153
154
/* Switch to little-endian mode */
154
155
filter -> filter_function = mbfl_filt_conv_utf16le_wchar ;
155
- filter -> cache = filter -> status = 0 ;
156
156
} else {
157
157
filter -> filter_function = mbfl_filt_conv_utf16be_wchar ;
158
158
if (n >= 0xD800 && n <= 0xDBFF ) {
@@ -165,7 +165,6 @@ int mbfl_filt_conv_utf16_wchar(int c, mbfl_convert_filter *filter)
165
165
} else if (n != 0xFEFF ) {
166
166
CK ((* filter -> output_function )(n , filter -> data ));
167
167
}
168
- filter -> cache = filter -> status = 0 ;
169
168
}
170
169
}
171
170
@@ -189,11 +188,11 @@ int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter)
189
188
filter -> status = 2 ;
190
189
} else if (n >= 0xDC00 && n <= 0xDFFF ) {
191
190
/* This is wrong; second part of surrogate pair has come first */
192
- CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
193
191
filter -> status = 0 ;
192
+ CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
194
193
} else {
195
- CK ((* filter -> output_function )(n , filter -> data ));
196
194
filter -> status = 0 ;
195
+ CK ((* filter -> output_function )(n , filter -> data ));
197
196
}
198
197
break ;
199
198
@@ -206,17 +205,17 @@ int mbfl_filt_conv_utf16be_wchar(int c, mbfl_convert_filter *filter)
206
205
n = ((filter -> cache & 0xFF ) << 8 ) | (c & 0xFF );
207
206
if (n >= 0xD800 && n <= 0xDBFF ) {
208
207
/* Wrong; that's the first half of a surrogate pair, not the second */
209
- CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
210
208
filter -> cache = n & 0x3FF ;
211
209
filter -> status = 2 ;
210
+ CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
212
211
} else if (n >= 0xDC00 && n <= 0xDFFF ) {
212
+ filter -> status = 0 ;
213
213
n = ((filter -> cache & 0x3FF00 ) << 2 ) + (n & 0x3FF ) + 0x10000 ;
214
214
CK ((* filter -> output_function )(n , filter -> data ));
215
- filter -> status = 0 ;
216
215
} else {
216
+ filter -> status = 0 ;
217
217
CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
218
218
CK ((* filter -> output_function )(n , filter -> data ));
219
- filter -> status = 0 ;
220
219
}
221
220
}
222
221
@@ -261,11 +260,11 @@ int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter)
261
260
filter -> status = 2 ;
262
261
} else if ((c & 0xfc ) == 0xdc ) {
263
262
/* This is wrong; the second part of the surrogate pair has come first */
264
- CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
265
263
filter -> status = 0 ;
264
+ CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
266
265
} else {
267
- CK ((* filter -> output_function )(filter -> cache + ((c & 0xff ) << 8 ), filter -> data ));
268
266
filter -> status = 0 ;
267
+ CK ((* filter -> output_function )(filter -> cache + ((c & 0xff ) << 8 ), filter -> data ));
269
268
}
270
269
break ;
271
270
@@ -279,19 +278,19 @@ int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter)
279
278
if (n >= 0xD800 && n <= 0xDBFF ) {
280
279
/* We previously saw the first part of a surrogate pair and were
281
280
* expecting the second part; this is another first part */
282
- CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
283
281
filter -> cache = n & 0x3FF ;
284
282
filter -> status = 2 ;
283
+ CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
285
284
} else if (n >= 0xDC00 && n <= 0xDFFF ) {
286
285
n = filter -> cache + ((c & 0x3 ) << 8 ) + 0x10000 ;
287
- CK ((* filter -> output_function )(n , filter -> data ));
288
286
filter -> status = 0 ;
287
+ CK ((* filter -> output_function )(n , filter -> data ));
289
288
} else {
290
289
/* The first part of a surrogate pair was followed by some other codepoint
291
290
* which is not part of a surrogate pair at all */
291
+ filter -> status = 0 ;
292
292
CK ((* filter -> output_function )(MBFL_BAD_INPUT , filter -> data ));
293
293
CK ((* filter -> output_function )(n , filter -> data ));
294
- filter -> status = 0 ;
295
294
}
296
295
break ;
297
296
}
0 commit comments