Skip to content

Improvements to TextEncodingConverter #142476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions llvm/lib/Support/TextEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ TextEncodingConverterICU::convertString(StringRef Source,
EC = U_ZERO_ERROR;
const char *Input = In;

Output = InputLength ? static_cast<char *>(Result.data()) : nullptr;
Output = static_cast<char *>(Result.data());
ucnv_convertEx(&*ToConvDesc, &*FromConvDesc, &Output, Result.end(), &Input,
In + InputLength, /*pivotStart=*/NULL,
/*pivotSource=*/NULL, /*pivotTarget=*/NULL,
Expand All @@ -175,8 +175,10 @@ TextEncodingConverterICU::convertString(StringRef Source,
if (Capacity < Result.max_size()) {
HandleOverflow(Capacity, Output, OutputLength, Result);
continue;
} else
} else {
Result.resize(Output - Result.data());
return std::error_code(E2BIG, std::generic_category());
}
}
// Some other error occured.
Result.resize(Output - Result.data());
Expand Down Expand Up @@ -271,10 +273,8 @@ TextEncodingConverterIconv::convertString(StringRef Source,
};

do {
// Setup the input. Use nullptr to reset iconv state if input length is
// zero.
size_t InputLength = Source.size();
char *Input = InputLength ? const_cast<char *>(Source.data()) : "";
char *Input = const_cast<char *>(Source.data());
Ret = iconv(ConvDesc, &Input, &InputLength, &Output, &OutputLength);
if (Ret != 0) {
if (auto EC = HandleError(Ret))
Expand Down
Loading