diff --git a/frameworks/cj/src/cj_input_method_controller.cpp b/frameworks/cj/src/cj_input_method_controller.cpp index 8b7c638a2f248f2bb86fb817a33379de2d11e2fd..3953e43873faf55eb53a597776f0bd209f811c92 100644 --- a/frameworks/cj/src/cj_input_method_controller.cpp +++ b/frameworks/cj/src/cj_input_method_controller.cpp @@ -409,6 +409,10 @@ std::u16string CjInputMethodController::GetLeftText(int32_t number) } IMSA_HILOGD("getLeftText runs"); char *text = getLeftText(number); + if (text == nullptr) { + IMSA_HILOGD("text is nullptr"); + return u""; + } auto ret = Str8ToStr16(std::string(text)); free(text); return ret; @@ -422,6 +426,10 @@ std::u16string CjInputMethodController::GetRightText(int32_t number) } IMSA_HILOGD("getRightText runs"); char *text = getRightText(number); + if (text == nullptr) { + IMSA_HILOGD("text is nullptr"); + return u""; + } auto ret = Str8ToStr16(std::string(text)); free(text); return ret;