From 0703f6457060272a86e1cafdeb4b7f51827fd456 Mon Sep 17 00:00:00 2001 From: yuanbo Date: Thu, 22 Jul 2021 20:11:58 +0800 Subject: [PATCH] fix codex scan issue Signed-off-by: yuanbo --- core/adapter/syscall/src/hdf_syscall_adapter.c | 3 ++- .../unittest/common/hdf_lite_manager_test.cpp | 4 ++-- test/unittest/manager/sample_driver_test.c | 15 +++++++++------ utils/src/hdf_cstring.c | 5 +++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/adapter/syscall/src/hdf_syscall_adapter.c b/core/adapter/syscall/src/hdf_syscall_adapter.c index 18fca415e..b89f24570 100644 --- a/core/adapter/syscall/src/hdf_syscall_adapter.c +++ b/core/adapter/syscall/src/hdf_syscall_adapter.c @@ -604,7 +604,9 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) continue; } if (HdfAdapterExitListenIoctl(thread->pfds[i].fd) == HDF_SUCCESS) { + thread->shouldStop = true; stopCount++; + break; } } @@ -612,7 +614,6 @@ static void HdfDevListenerThreadDestroy(struct HdfDevListenerThread *thread) thread->shouldStop = true; HDF_LOGE("%s:failed to exit listener thread with ioctl, will go async way", __func__); } - return; } case LISTENER_STARTED: diff --git a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp index 623e4eb42..264a2fd74 100644 --- a/core/manager/test/unittest/common/hdf_lite_manager_test.cpp +++ b/core/manager/test/unittest/common/hdf_lite_manager_test.cpp @@ -84,7 +84,7 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0) int32_t ret = HDF_FAILURE; struct HdfSBuf *data = NULL; struct HdfIoService *ioService = HdfIoServiceBind(SAMPLE_SERVICE); - EXPECT_TRUE(ioService != NULL); + ASSERT_TRUE(ioService != NULL); data = HdfSBufObtainDefaultSize(); EXPECT_TRUE(data != NULL); EXPECT_TRUE(HdfSbufWriteString(data, "sample_driver")); @@ -118,7 +118,7 @@ HWTEST_F(HdfManagerTest, HdfRegisterDevice001, TestSize.Level0) HWTEST_F(HdfManagerTest, HdfGetServiceNameByDeviceClass001, TestSize.Level0) { struct HdfSBuf *data = HdfSBufObtain(1000); - EXPECT_TRUE(data != NULL); + ASSERT_TRUE(data != NULL); int32_t ret = HdfGetServiceNameByDeviceClass(DEVICE_CLASS_DEFAULT, data); EXPECT_TRUE(ret == HDF_SUCCESS); bool flag = false; diff --git a/test/unittest/manager/sample_driver_test.c b/test/unittest/manager/sample_driver_test.c index 84c3b6a58..609787660 100644 --- a/test/unittest/manager/sample_driver_test.c +++ b/test/unittest/manager/sample_driver_test.c @@ -72,6 +72,9 @@ int32_t SampleDriverSendEvent(struct HdfDeviceIoClient *client, int id, struct H int32_t SampleDriverPowerStateInject(uint32_t powerState) { struct IDevmgrService *devmgrService = DevmgrServiceGetInstance(); + if (devmgrService == NULL || devmgrService->PowerStateChange == NULL) { + return HDF_ERR_INVALID_OBJECT; + } int ret = devmgrService->PowerStateChange(devmgrService, powerState); HDF_LOGI("%s: inject power state(%d) done, ret = %d", __func__, powerState, ret); @@ -115,7 +118,7 @@ int32_t SampleDriverDispatch(struct HdfDeviceIoClient *client, int cmdId, struct int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) { - HDF_LOGD("%s::enter!, deviceObject=%p", __func__, deviceObject); + HDF_LOGD("%s::enter", __func__); if (deviceObject == NULL) { return HDF_FAILURE; } @@ -130,25 +133,25 @@ int HdfSampleDriverBind(struct HdfDeviceObject *deviceObject) int HdfSampleDozeResume(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } int HdfSampleDozeSuspend(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } int HdfSampleResume(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } int HdfSampleSuspend(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s:called, object = %llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s:called", __func__); return HDF_SUCCESS; } @@ -159,7 +162,7 @@ struct SampleDriverPmListener { int HdfSampleDriverInit(struct HdfDeviceObject *deviceObject) { - HDF_LOGI("%s::enter!, deviceObject=%llx", __func__, (uint64_t)deviceObject); + HDF_LOGI("%s::enter!", __func__); if (deviceObject == NULL) { HDF_LOGE("%s::ptr is null!", __func__); return HDF_FAILURE; diff --git a/utils/src/hdf_cstring.c b/utils/src/hdf_cstring.c index 4b30bb2e7..761e21659 100644 --- a/utils/src/hdf_cstring.c +++ b/utils/src/hdf_cstring.c @@ -11,6 +11,8 @@ #include "osal_mem.h" #include "securec.h" +#define CSTRING_MAX 1024 + uint32_t HdfStringMakeHashKey(const char *key, uint32_t mask) { uint32_t hashValue = 0; @@ -26,6 +28,9 @@ struct HdfCString *HdfCStringObtain(const char *str) struct HdfCString *instance = NULL; if (str != NULL) { size_t strLen = strlen(str); + if (strLen > CSTRING_MAX) { + return NULL; + } size_t size = sizeof(struct HdfCString) + strLen + 1; instance = (struct HdfCString *)OsalMemCalloc(size); if (instance == NULL) { -- Gitee