From bea4afba1ab0fb1104505357dad46b0dcb3b1916 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Mon, 14 Apr 2025 20:16:38 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=B3=95=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E6=94=AF=E6=8C=81=E6=84=9F=E7=9F=A5=E5=88=B0=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=A1=86=E4=B8=AD=E7=9A=84=E5=8D=A0=E4=BD=8D=E6=96=87?= =?UTF-8?q?=E6=9C=AC=E5=92=8C=E6=89=80=E5=B1=9EAbility=E7=9A=84=E5=90=8D?= =?UTF-8?q?=E5=AD=97=E4=BC=98,=E5=8C=96=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- common/src/itypes_util.cpp | 3 +-- .../include/input_attribute.h | 7 ------- .../src/input_method_controller.cpp | 6 ++---- .../ndk/src/inputmethod_text_config_capi.cpp | 2 +- .../kits/c/inputmethod_text_config_capi.h | 9 ++++++--- .../src/inputmethod_controller_capi_test.cpp | 19 +++++++++++++++---- 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/common/src/itypes_util.cpp b/common/src/itypes_util.cpp index 994a466dd..6df768c01 100644 --- a/common/src/itypes_util.cpp +++ b/common/src/itypes_util.cpp @@ -560,8 +560,7 @@ bool ITypesUtil::Unmarshalling(RequestKeyboardReason &output, MessageParcel &dat int32_t ITypesUtil::CountUtf16Chars(const std::u16string &in) { int32_t ret = u_countChar32(in.data(), in.size()); - IMSA_HILOGD("size:%{public}zu,ret:%{public}d, data:[%{public}s]", - in.size(), ret, Str16ToStr8(in).c_str()); + IMSA_HILOGD("size:%{public}zu,ret:%{public}d", in.size(), ret); return ret; } } // namespace MiscServices diff --git a/frameworks/native/inputmethod_controller/include/input_attribute.h b/frameworks/native/inputmethod_controller/include/input_attribute.h index 3ce3769c2..91dbf35ac 100644 --- a/frameworks/native/inputmethod_controller/include/input_attribute.h +++ b/frameworks/native/inputmethod_controller/include/input_attribute.h @@ -82,12 +82,6 @@ struct InputAttribute { inputOption == info.inputOption && isTextPreviewSupported == info.isTextPreviewSupported; } - inline std::string ToUtf8(const std::u16string &in) const - { - std::wstring_convert, char16_t> converter; - return converter.to_bytes(in); - } - inline std::string ToString() const { std::stringstream ss; @@ -96,7 +90,6 @@ struct InputAttribute { << "isTextPreviewSupported:" << isTextPreviewSupported << "bundleName:" << bundleName << "immersiveMode:" << immersiveMode << "windowId:" << windowId << "callingDisplayId:" << callingDisplayId - << "placeholder:" << ToUtf8(placeholder) << "abilityName:" << ToUtf8(abilityName) << "]"; return ss.str(); } diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index c2175d30e..3adf8c28e 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -253,15 +253,13 @@ int32_t InputMethodController::IsValidTextConfig(const TextConfig &textConfig) } int32_t uft16CharLen = ITypesUtil::CountUtf16Chars(textConfig.inputAttribute.placeholder); if (uft16CharLen > MAX_PLACEHOLDER_SIZE) { - IMSA_HILOGE("invalid placeholder:%{public}s over limit num:%{public}d", - Str16ToStr8(textConfig.inputAttribute.placeholder).c_str(), uft16CharLen); + IMSA_HILOGE("invalid placeholder over limit num:%{public}d", uft16CharLen); return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; } uft16CharLen = ITypesUtil::CountUtf16Chars(textConfig.inputAttribute.abilityName); if (uft16CharLen > MAX_ABILITY_NAME_SIZE) { - IMSA_HILOGE("invalid abilityName:%{public}s, over limit num:%{public}d", - Str16ToStr8(textConfig.inputAttribute.abilityName).c_str(), uft16CharLen); + IMSA_HILOGE("invalid abilityName over limit num:%{public}d", uft16CharLen); return ErrorCode::ERROR_PARAMETER_CHECK_FAILED; } return ErrorCode::NO_ERROR; diff --git a/frameworks/ndk/src/inputmethod_text_config_capi.cpp b/frameworks/ndk/src/inputmethod_text_config_capi.cpp index bfdcc8c6a..f7c9d3ea8 100644 --- a/frameworks/ndk/src/inputmethod_text_config_capi.cpp +++ b/frameworks/ndk/src/inputmethod_text_config_capi.cpp @@ -355,7 +355,7 @@ InputMethod_ErrorCode OH_TextConfig_GetAbilityName(InputMethod_TextConfig *confi config->abilityNameLength = ENDING_SYMBOL_SIZE; config->abilityName[0] = UTF16_ENDING_SYMBOL; } - IMSA_HILOGD("curLen:%{public}zu,inputLen:%{public}zu", config->placeholderLength, *length); + IMSA_HILOGD("curLen:%{public}zu,inputLen:%{public}zu", config->abilityNameLength, *length); if ((*length) < config->abilityNameLength) { IMSA_HILOGE("input memory is less than the length of the obtained memory. actual length:%{public}zu", config->abilityNameLength); diff --git a/interfaces/kits/c/inputmethod_text_config_capi.h b/interfaces/kits/c/inputmethod_text_config_capi.h index 4044f559c..a7e3ac017 100644 --- a/interfaces/kits/c/inputmethod_text_config_capi.h +++ b/interfaces/kits/c/inputmethod_text_config_capi.h @@ -265,10 +265,12 @@ InputMethod_ErrorCode OH_TextConfig_GetWindowId(InputMethod_TextConfig *config, /** * @brief Get placeholder into TextConfig. * - * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set. + * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from. * @param placeholder Returns the placeholder. which is defined in {@link InputMethod_TextConfig}. * The user needs to allocate memory. * @param length Input and output parameters. The input is the size requested by the user (unit: char16_t). + * Check the validity of the memory requested by the user based on the input length. + * If the value is smaller than the actual size, the actual length is returned. * The length, which is defined in {@link InputMethod_TextConfig}. * @return Returns a specific error code. * {@link IME_ERR_OK} - success. @@ -283,11 +285,12 @@ InputMethod_ErrorCode OH_TextConfig_GetPlaceholder(InputMethod_TextConfig *confi /** * @brief Get abilityName into TextConfig. * - * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be set. + * @param config Represents a pointer to an {@link InputMethod_TextConfig} instance which will be get from. * @param abilityName The abilityName, which is defined in {@link InputMethod_TextConfig}. * The free function needs to be called externally to release the internal requested memory. * @param length Input and output parameters. The input is the size requested by the user (unit: char16_t), - * returns the size of the ability name. + * Check the validity of the memory requested by the user based on the input length. + * If the value is smaller than the actual size, the actual length is returned. * The length, which is defined in {@link InputMethod_TextConfig}. * @return Returns a specific error code. * {@link IME_ERR_OK} - success. diff --git a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp index 02086db22..7b197a3c3 100644 --- a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp +++ b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp @@ -1584,6 +1584,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_001, TestSi size_t outLen = 513; char16_t *pOut = new (std::nothrow) char16_t[outLen]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } ret = OH_TextConfig_GetPlaceholder(config, pOut, nullptr); @@ -1600,11 +1601,13 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_001, TestSi ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_PARAMCHECK); std::u16string out(pOut, outLen); - EXPECT_EQ(out.compare(input), 1); + bool bGreater = out.size() > input.size(); + EXPECT_EQ(bGreater, true); delete []pOut; outLen = input.size() -1; pOut = new (std::nothrow) char16_t[outLen]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); @@ -1629,6 +1632,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_002, TestSi size_t outLen = 512; char16_t *pOut = new (std::nothrow) char16_t[outLen]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); @@ -1662,12 +1666,14 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_003, TestSi size_t outLen = input.size() + 1; char16_t *pOut = new (std::nothrow) char16_t[outLen]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_OK); std::u16string out(pOut, outLen); - EXPECT_EQ(out.compare(input), 1); + bool bGreater = out.size() > input.size(); + EXPECT_EQ(bGreater, true); delete []pOut; input.append(u"a"); IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); @@ -1695,6 +1701,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_001, TestSi size_t outLen = 66; char16_t *pOut = new (std::nothrow) char16_t[outLen]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } ret = OH_TextConfig_GetAbilityName(config, pOut, nullptr); @@ -1713,7 +1720,8 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_001, TestSi std::u16string out(pOut, outLen); IMSA_HILOGI("outLen:%{public}zu,out:%{public}s,outSize:%{public}zu", outLen, Str16ToStr8(out).c_str(), out.size()); - EXPECT_EQ(out.compare(input), 1); + bool bGreater = out.size() > input.size(); + EXPECT_EQ(bGreater, true); outLen = input.size(); ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_PARAMCHECK); @@ -1766,6 +1774,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSi size_t outLen = input.size() + 1; char16_t *pOut = new (std::nothrow) char16_t[outLen]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen); @@ -1773,7 +1782,8 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSi std::u16string out(pOut, outLen); IMSA_HILOGI("outLen:%{public}zu,input:%{public}s,outSize:%{public}zu,inputSize:%{public}zu", outLen, Str16ToStr8(input).c_str(), out.size(), input.size()); - EXPECT_EQ(out.compare(input), 1); + bool bGreater = out.size() > input.size(); + EXPECT_EQ(bGreater, true); delete []pOut; input.append(u"a"); IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); @@ -1786,6 +1796,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSi EXPECT_EQ(ret, IME_ERR_OK); pOut = new char16_t[66]; if (pOut == nullptr) { + OH_TextConfig_Destroy(config); return; } outLen = 33; -- Gitee From f6a9ee28d79f53469587d6eb0e96970da7ccf247 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 15 Apr 2025 11:31:33 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../src/inputmethod_controller_capi_test.cpp | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp index 7b197a3c3..de71a2394 100644 --- a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp +++ b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp @@ -1762,14 +1762,35 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSi EXPECT_EQ(ret, IME_ERR_OK); ret = OH_TextConfig_SetAbilityName(config, nullptr, 1); EXPECT_EQ(ret, IME_ERR_OK); + char16_t *input = new (std::nothrow) char16_t(u'0'); + if (input != nullptr) { + OH_TextConfig_Destroy(config); + return; + } + ret = OH_TextConfig_SetAbilityName(config, input, 0); + EXPECT_EQ(ret, IME_ERR_OK); + ret = OH_TextConfig_SetAbilityName(config, input, 1); + EXPECT_EQ(ret, IME_ERR_OK); ret = OH_TextConfig_SetAbilityName(nullptr, nullptr, 1); EXPECT_EQ(ret, IME_ERR_NULL_POINTER); + delete input; + OH_TextConfig_Destroy(config); +} + +/** + * @tc.name: OH_TextConfig_SetAbilityName_004 + * @tc.desc: Invalid test input parameter + * @tc.type: FUNC + */ +HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_004, TestSize.Level0) { + auto config = OH_TextConfig_Create(); + ASSERT_NE(nullptr, config); std::u16string input = u""; for (int i = 0; i < 32; ++i) { input.append(u"𪛊"); } IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); - ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size()); + auto ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size()); EXPECT_EQ(ret, IME_ERR_OK); size_t outLen = input.size() + 1; char16_t *pOut = new (std::nothrow) char16_t[outLen]; @@ -1794,7 +1815,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSi IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", charInputLen, Str16ToStr8(input).c_str()); ret = OH_TextConfig_SetAbilityName(config, charInput, charInputLen); EXPECT_EQ(ret, IME_ERR_OK); - pOut = new char16_t[66]; + pOut = new (std::nothrow) char16_t[66]; if (pOut == nullptr) { OH_TextConfig_Destroy(config); return; -- Gitee From 443d39059d3a21f492417883e3d62e8520a49ec7 Mon Sep 17 00:00:00 2001 From: qianyong325 Date: Tue, 15 Apr 2025 17:08:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qianyong325 --- .../src/inputmethod_controller_capi_test.cpp | 78 ++++--------------- 1 file changed, 17 insertions(+), 61 deletions(-) diff --git a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp index de71a2394..9bd3467bc 100644 --- a/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp +++ b/test/unittest/cpp_test/src/inputmethod_controller_capi_test.cpp @@ -1582,11 +1582,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_001, TestSi ret = OH_TextConfig_GetPlaceholder(config, nullptr, nullptr); EXPECT_EQ(ret, IME_ERR_NULL_POINTER); size_t outLen = 513; - char16_t *pOut = new (std::nothrow) char16_t[outLen]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + char16_t pOut[513] = {}; ret = OH_TextConfig_GetPlaceholder(config, pOut, nullptr); EXPECT_EQ(ret, IME_ERR_NULL_POINTER); outLen = 1; @@ -1601,18 +1597,10 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_001, TestSi ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_PARAMCHECK); std::u16string out(pOut, outLen); - bool bGreater = out.size() > input.size(); - EXPECT_EQ(bGreater, true); - delete []pOut; - outLen = input.size() -1; - pOut = new (std::nothrow) char16_t[outLen]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + EXPECT_GT(out.size(), input.size()); + outLen = 4; ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_PARAMCHECK); - delete []pOut; OH_TextConfig_Destroy(config); } @@ -1630,15 +1618,10 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_002, TestSi ret = OH_TextConfig_SetPlaceholder(config, nullptr, 0); EXPECT_EQ(ret, IME_ERR_OK); size_t outLen = 512; - char16_t *pOut = new (std::nothrow) char16_t[outLen]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + char16_t pOut[512] = {}; ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_OK); EXPECT_EQ(outLen, 1); - delete []pOut; OH_TextConfig_Destroy(config); } @@ -1663,18 +1646,12 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetPlaceholder_003, TestSi IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); ret = OH_TextConfig_SetPlaceholder(config, input.data(), input.size()); EXPECT_EQ(ret, IME_ERR_OK); - size_t outLen = input.size() + 1; - char16_t *pOut = new (std::nothrow) char16_t[outLen]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + size_t outLen = 513; + char16_t pOut[513] = {}; ret = OH_TextConfig_GetPlaceholder(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_OK); std::u16string out(pOut, outLen); - bool bGreater = out.size() > input.size(); - EXPECT_EQ(bGreater, true); - delete []pOut; + EXPECT_GT(out.size(), input.size()); input.append(u"a"); IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); ret = OH_TextConfig_SetPlaceholder(config, input.data(), input.size()); @@ -1699,11 +1676,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_001, TestSi ret = OH_TextConfig_GetAbilityName(config, nullptr, nullptr); EXPECT_EQ(ret, IME_ERR_NULL_POINTER); size_t outLen = 66; - char16_t *pOut = new (std::nothrow) char16_t[outLen]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + char16_t pOut[66] = {}; ret = OH_TextConfig_GetAbilityName(config, pOut, nullptr); EXPECT_EQ(ret, IME_ERR_NULL_POINTER); outLen = 1; @@ -1720,8 +1693,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_001, TestSi std::u16string out(pOut, outLen); IMSA_HILOGI("outLen:%{public}zu,out:%{public}s,outSize:%{public}zu", outLen, Str16ToStr8(out).c_str(), out.size()); - bool bGreater = out.size() > input.size(); - EXPECT_EQ(bGreater, true); + EXPECT_GT(out.size(), input.size()); outLen = input.size(); ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_PARAMCHECK); @@ -1762,18 +1734,13 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_003, TestSi EXPECT_EQ(ret, IME_ERR_OK); ret = OH_TextConfig_SetAbilityName(config, nullptr, 1); EXPECT_EQ(ret, IME_ERR_OK); - char16_t *input = new (std::nothrow) char16_t(u'0'); - if (input != nullptr) { - OH_TextConfig_Destroy(config); - return; - } + char16_t input[] = u"0"; ret = OH_TextConfig_SetAbilityName(config, input, 0); EXPECT_EQ(ret, IME_ERR_OK); ret = OH_TextConfig_SetAbilityName(config, input, 1); EXPECT_EQ(ret, IME_ERR_OK); ret = OH_TextConfig_SetAbilityName(nullptr, nullptr, 1); EXPECT_EQ(ret, IME_ERR_NULL_POINTER); - delete input; OH_TextConfig_Destroy(config); } @@ -1792,20 +1759,14 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_004, TestSi IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); auto ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size()); EXPECT_EQ(ret, IME_ERR_OK); - size_t outLen = input.size() + 1; - char16_t *pOut = new (std::nothrow) char16_t[outLen]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + size_t outLen = 65; + char16_t pOut[65] = {}; ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen); EXPECT_EQ(ret, IME_ERR_OK); std::u16string out(pOut, outLen); IMSA_HILOGI("outLen:%{public}zu,input:%{public}s,outSize:%{public}zu,inputSize:%{public}zu", outLen, Str16ToStr8(input).c_str(), out.size(), input.size()); - bool bGreater = out.size() > input.size(); - EXPECT_EQ(bGreater, true); - delete []pOut; + EXPECT_GT(out.size(), input.size()); input.append(u"a"); IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", input.size(), Str16ToStr8(input).c_str()); ret = OH_TextConfig_SetAbilityName(config, input.data(), input.size()); @@ -1815,18 +1776,13 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_SetAbilityName_004, TestSi IMSA_HILOGI("inputLen:%{public}zu,input:%{public}s", charInputLen, Str16ToStr8(input).c_str()); ret = OH_TextConfig_SetAbilityName(config, charInput, charInputLen); EXPECT_EQ(ret, IME_ERR_OK); - pOut = new (std::nothrow) char16_t[66]; - if (pOut == nullptr) { - OH_TextConfig_Destroy(config); - return; - } + char16_t outChar[66] = {}; outLen = 33; - ret = OH_TextConfig_GetAbilityName(config, pOut, &outLen); + ret = OH_TextConfig_GetAbilityName(config, outChar, &outLen); EXPECT_EQ(ret, IME_ERR_OK); - out = std::u16string(pOut, outLen); - auto utf8Out = Str16ToStr8(pOut); + out = std::u16string(outChar, outLen); + auto utf8Out = Str16ToStr8(outChar); IMSA_HILOGI("outLen:%{public}zu,out:%{public}s, utf8len:%{public}zu", outLen, utf8Out.c_str(), utf8Out.size()); - delete []pOut; OH_TextConfig_Destroy(config); } } // namespace \ No newline at end of file -- Gitee