Skip to content

Commit 652f4e9

Browse files
abhina-sreemahesh-attarde
authored andcommitted
Improvements to TextEncodingConverter (llvm#142476)
This patch addresses the follow-up comments on PR llvm#138893
1 parent d763be5 commit 652f4e9

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

llvm/lib/Support/TextEncoding.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ TextEncodingConverterICU::convertString(StringRef Source,
161161
EC = U_ZERO_ERROR;
162162
const char *Input = In;
163163

164-
Output = InputLength ? static_cast<char *>(Result.data()) : nullptr;
164+
Output = static_cast<char *>(Result.data());
165165
ucnv_convertEx(&*ToConvDesc, &*FromConvDesc, &Output, Result.end(), &Input,
166166
In + InputLength, /*pivotStart=*/NULL,
167167
/*pivotSource=*/NULL, /*pivotTarget=*/NULL,
@@ -172,8 +172,10 @@ TextEncodingConverterICU::convertString(StringRef Source,
172172
if (Capacity < Result.max_size()) {
173173
HandleOverflow(Capacity, Output, OutputLength, Result);
174174
continue;
175-
} else
175+
} else {
176+
Result.resize(Output - Result.data());
176177
return std::error_code(E2BIG, std::generic_category());
178+
}
177179
}
178180
// Some other error occured.
179181
Result.resize(Output - Result.data());
@@ -268,10 +270,8 @@ TextEncodingConverterIconv::convertString(StringRef Source,
268270
};
269271

270272
do {
271-
// Setup the input. Use nullptr to reset iconv state if input length is
272-
// zero.
273273
size_t InputLength = Source.size();
274-
char *Input = const_cast<char *>(InputLength ? Source.data() : "");
274+
char *Input = const_cast<char *>(Source.data());
275275
Ret = iconv(ConvDesc, &Input, &InputLength, &Output, &OutputLength);
276276
if (Ret != 0) {
277277
if (auto EC = HandleError(Ret))

0 commit comments

Comments
 (0)