Skip to content

Commit 19f64df

Browse files
committed
reset iconv if failed, cause overflow in testcase
1 parent 3980bf5 commit 19f64df

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

llvm/lib/Support/CharSet.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static void HandleOverflow(size_t &Capacity, char *&Output,
6666
Capacity = (Capacity < std::numeric_limits<size_t>::max() / 2)
6767
? 2 * Capacity
6868
: std::numeric_limits<size_t>::max();
69+
Result.resize(0);
6970
Result.resize_for_overwrite(Capacity);
7071
Output = static_cast<char *>(Result.data());
7172
OutputLength = Capacity;
@@ -205,6 +206,8 @@ std::error_code CharSetConverterIconv::convert(StringRef Source,
205206
// An error occured. Check if we can gracefully handle it.
206207
if (errno == E2BIG && Capacity < std::numeric_limits<size_t>::max()) {
207208
HandleOverflow(Capacity, Output, OutputLength, Result);
209+
// Reset converter
210+
iconv(ConvDesc, nullptr, nullptr, nullptr, nullptr);
208211
return std::error_code();
209212
} else {
210213
// Some other error occured.

llvm/unittests/Support/CharSetTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ TEST(CharSet, RoundTrip) {
156156
TEST(CharSet, ShiftState2022) {
157157
// Earth string.
158158
StringRef Src(EarthUTF);
159-
SmallString<64> Dst;
159+
SmallString<8> Dst;
160160

161161
ErrorOr<CharSetConverter> ConvTo2022 =
162162
CharSetConverter::create("UTF-8", "ISO-2022-JP");

0 commit comments

Comments
 (0)