@@ -161,7 +161,7 @@ TextEncodingConverterICU::convertString(StringRef Source,
161
161
EC = U_ZERO_ERROR;
162
162
const char *Input = In;
163
163
164
- Output = InputLength ? static_cast <char *>(Result.data ()) : nullptr ;
164
+ Output = static_cast <char *>(Result.data ());
165
165
ucnv_convertEx (&*ToConvDesc, &*FromConvDesc, &Output, Result.end (), &Input,
166
166
In + InputLength, /* pivotStart=*/ NULL ,
167
167
/* pivotSource=*/ NULL , /* pivotTarget=*/ NULL ,
@@ -172,8 +172,10 @@ TextEncodingConverterICU::convertString(StringRef Source,
172
172
if (Capacity < Result.max_size ()) {
173
173
HandleOverflow (Capacity, Output, OutputLength, Result);
174
174
continue ;
175
- } else
175
+ } else {
176
+ Result.resize (Output - Result.data ());
176
177
return std::error_code (E2BIG, std::generic_category ());
178
+ }
177
179
}
178
180
// Some other error occured.
179
181
Result.resize (Output - Result.data ());
@@ -268,10 +270,8 @@ TextEncodingConverterIconv::convertString(StringRef Source,
268
270
};
269
271
270
272
do {
271
- // Setup the input. Use nullptr to reset iconv state if input length is
272
- // zero.
273
273
size_t InputLength = Source.size ();
274
- char *Input = const_cast <char *>(InputLength ? Source.data () : " " );
274
+ char *Input = const_cast <char *>(Source.data ());
275
275
Ret = iconv (ConvDesc, &Input, &InputLength, &Output, &OutputLength);
276
276
if (Ret != 0 ) {
277
277
if (auto EC = HandleError (Ret))
0 commit comments