mirror of
https://gitee.com/openharmony/inputmethod_imf
synced 2024-11-23 06:40:06 +00:00
!1523 fix:check null pointer before access
Merge pull request !1523 from 吴成文/master
This commit is contained in:
commit
f4a7feab14
@ -21,7 +21,7 @@ InputMethod_ErrorCode ErrorCodeConvert(int32_t code);
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif /* __cplusplus */
|
||||
InputMethod_ErrorCode IsValidInputMethodProxy(InputMethod_InputMethodProxy *inputMethodProxy);
|
||||
InputMethod_ErrorCode IsValidInputMethodProxy(const InputMethod_InputMethodProxy *inputMethodProxy);
|
||||
void ClearInputMethodProxy(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ struct InputMethod_InputMethodProxy {
|
||||
InputMethod_InputMethodProxy *g_inputMethodProxy = nullptr;
|
||||
std::mutex g_textEditorProxyMapMutex;
|
||||
|
||||
InputMethod_ErrorCode IsValidInputMethodProxy(InputMethod_InputMethodProxy *inputMethodProxy)
|
||||
InputMethod_ErrorCode IsValidInputMethodProxy(const InputMethod_InputMethodProxy *inputMethodProxy)
|
||||
{
|
||||
if (inputMethodProxy == nullptr) {
|
||||
IMSA_HILOGE("inputMethodProxy is nullptr");
|
||||
@ -53,7 +53,7 @@ InputMethod_ErrorCode IsValidInputMethodProxy(InputMethod_InputMethodProxy *inpu
|
||||
return IME_ERR_PARAMCHECK;
|
||||
}
|
||||
|
||||
if (g_inputMethodProxy->attached == false) {
|
||||
if (!(g_inputMethodProxy->attached)) {
|
||||
IMSA_HILOGE("g_inputMethodProxy is not attached");
|
||||
return IME_ERR_DETACHED;
|
||||
}
|
||||
@ -118,22 +118,8 @@ static int32_t IsValidTextEditorProxy(InputMethod_TextEditorProxy *textEditor)
|
||||
return IME_ERR_OK;
|
||||
}
|
||||
|
||||
InputMethod_ErrorCode OH_InputMethodController_Attach(InputMethod_TextEditorProxy *textEditor,
|
||||
InputMethod_AttachOptions *options, InputMethod_InputMethodProxy **inputMethodProxy)
|
||||
static TextConfig ConstructTextConfig(const InputMethod_TextConfig &config)
|
||||
{
|
||||
if ((IsValidTextEditorProxy(textEditor) != IME_ERR_OK) || options == nullptr || inputMethodProxy == nullptr) {
|
||||
IMSA_HILOGE("invalid parameter");
|
||||
return IME_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
InputMethod_ErrorCode errCode = GetInputMethodProxy(textEditor);
|
||||
if (errCode != IME_ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
InputMethod_TextConfig config;
|
||||
textEditor->getTextConfigFunc(textEditor, &config);
|
||||
|
||||
TextConfig textConfig = {
|
||||
.inputAttribute = {
|
||||
.inputPattern = static_cast<InputMethod_TextInputType>(config.inputType),
|
||||
@ -155,11 +141,34 @@ InputMethod_ErrorCode OH_InputMethodController_Attach(InputMethod_TextEditorProx
|
||||
.height = config.avoidInfo.height,
|
||||
};
|
||||
|
||||
return textConfig;
|
||||
}
|
||||
|
||||
InputMethod_ErrorCode OH_InputMethodController_Attach(InputMethod_TextEditorProxy *textEditor,
|
||||
InputMethod_AttachOptions *options, InputMethod_InputMethodProxy **inputMethodProxy)
|
||||
{
|
||||
if ((IsValidTextEditorProxy(textEditor) != IME_ERR_OK) || options == nullptr || inputMethodProxy == nullptr) {
|
||||
IMSA_HILOGE("invalid parameter");
|
||||
return IME_ERR_NULL_POINTER;
|
||||
}
|
||||
|
||||
InputMethod_ErrorCode errCode = GetInputMethodProxy(textEditor);
|
||||
if (errCode != IME_ERR_OK) {
|
||||
return errCode;
|
||||
}
|
||||
|
||||
InputMethod_TextConfig config;
|
||||
textEditor->getTextConfigFunc(textEditor, &config);
|
||||
|
||||
auto textConfig = ConstructTextConfig(config);
|
||||
|
||||
auto controller = InputMethodController::GetInstance();
|
||||
OHOS::sptr<NativeTextChangedListener> listener = nullptr;
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(g_textEditorProxyMapMutex);
|
||||
listener = g_inputMethodProxy->listener;
|
||||
if (g_inputMethodProxy != nullptr) {
|
||||
listener = g_inputMethodProxy->listener;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t err = controller->Attach(listener, options->showKeyboard, textConfig);
|
||||
|
@ -236,7 +236,7 @@ int32_t NativeTextChangedListener::ReceivePrivateCommand(
|
||||
}
|
||||
|
||||
size_t index = 0;
|
||||
for (auto &item : privateCommand) {
|
||||
for (const auto &item : privateCommand) {
|
||||
command[index] = new InputMethod_PrivateCommand();
|
||||
command[index]->key = item.first;
|
||||
command[index]->value = item.second;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
using namespace testing::ext;
|
||||
class InputMethodControllerCapiTest : public testing::Test { };
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: TestCursorInfo_001
|
||||
* @tc.desc: create and destroy TestCursorInfo success
|
||||
@ -557,6 +557,7 @@ HWTEST_F(InputMethodControllerCapiTest, OH_TextConfig_GetSelection_001, TestSize
|
||||
InputMethod_TextConfig *config = OH_TextConfig_Create();
|
||||
ASSERT_NE(config, nullptr);
|
||||
ret = OH_TextConfig_GetSelection(config, nullptr, nullptr);
|
||||
EXPECT_EQ(IME_ERR_NULL_POINTER, ret);
|
||||
int32_t start = 0;
|
||||
ret = OH_TextConfig_GetSelection(config, &start, nullptr);
|
||||
EXPECT_EQ(ret, IME_ERR_NULL_POINTER);
|
||||
@ -1512,3 +1513,4 @@ HWTEST_F(InputMethodControllerCapiTest, TestAttachWithNorrmalParam_001, TestSize
|
||||
OH_AttachOptions_Destroy(options);
|
||||
OH_TextEditorProxy_Destroy(textEditorProxy);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user