[llvm] Improvments to TextEncodingConverter (PR #142476)
Abhina Sree via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 2 13:08:05 PDT 2025
https://github.com/abhina-sree created https://github.com/llvm/llvm-project/pull/142476
This patch addresses the follow-up comments on PR https://github.com/llvm/llvm-project/pull/138893
>From 057be53192da595232c3273ce4a1963f751b0680 Mon Sep 17 00:00:00 2001
From: Abhina Sreeskantharajan <Abhina.Sreeskantharajan at ibm.com>
Date: Mon, 2 Jun 2025 16:06:59 -0400
Subject: [PATCH] address further comments on TextEncodingConverter
---
llvm/lib/Support/TextEncoding.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Support/TextEncoding.cpp b/llvm/lib/Support/TextEncoding.cpp
index 969dd419ede72..72a011c85e0eb 100644
--- a/llvm/lib/Support/TextEncoding.cpp
+++ b/llvm/lib/Support/TextEncoding.cpp
@@ -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,
@@ -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());
@@ -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))
More information about the llvm-commits
mailing list