From 618138a9b53d94d57b10dea4c21578778cec24b9 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Thu, 13 Apr 2023 18:30:42 +1000 Subject: [PATCH] Fix #1380, Light coding standards cleanup --- .github/workflows/codeql-cfe-build.yml | 2 +- .github/workflows/codeql-osal-default.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- src/bsp/pc-rtems/src/bsp_start.c | 3 ++- .../tasking-example/tasking-example.c | 7 +++++-- src/os/posix/src/os-impl-tasks.c | 2 +- src/os/rtems/src/os-impl-loader.c | 2 +- src/os/shared/src/osapi-common.c | 2 +- src/os/shared/src/osapi-idmap.c | 3 ++- src/tests/mutex-test/mutex-test.c | 5 ++--- src/tests/queue-test/queue-test.c | 4 +++- .../shared/src/coveragetest-binsem.c | 6 +++--- .../shared/src/coveragetest-countsem.c | 6 +++--- .../shared/src/coveragetest-file.c | 3 +-- .../shared/src/coveragetest-filesys.c | 6 +++--- .../shared/src/coveragetest-idmap.c | 14 ++++++------- .../shared/src/coveragetest-module.c | 8 ++++---- .../ut-stubs/src/libc-stdlib-stubs.c | 2 +- src/unit-tests/inc/ut_os_support.h | 2 ++ .../oscore-test/ut_oscore_misc_test.c | 4 ++-- .../oscore-test/ut_oscore_queue_test.c | 2 +- .../oscore-test/ut_oscore_select_test.c | 3 ++- .../oscore-test/ut_oscore_task_test.c | 2 +- .../osfile-test/ut_osfile_fileio_test.c | 10 +++++++--- .../osfilesys-test/ut_osfilesys_diskio_test.c | 8 ++++---- src/unit-tests/ostimer-test/ut_ostimer_test.c | 14 ++++++++++--- .../ostimer-test/ut_ostimer_timerio_test.c | 6 ++++-- src/ut-stubs/osapi-printf-handlers.c | 2 +- ut_assert/src/uttools.c | 20 ++++++++++++++++--- 29 files changed, 94 insertions(+), 58 deletions(-) diff --git a/.github/workflows/codeql-cfe-build.yml b/.github/workflows/codeql-cfe-build.yml index 9a4a5099e..76d1557e4 100644 --- a/.github/workflows/codeql-cfe-build.yml +++ b/.github/workflows/codeql-cfe-build.yml @@ -8,6 +8,6 @@ jobs: codeql: name: CodeQl Analysis uses: nasa/cFS/.github/workflows/codeql-reusable.yml@main - with: + with: component-path: osal make: 'make -C build/native/default_cpu1/osal' diff --git a/.github/workflows/codeql-osal-default.yml b/.github/workflows/codeql-osal-default.yml index 748faa93c..ca4349bf0 100644 --- a/.github/workflows/codeql-osal-default.yml +++ b/.github/workflows/codeql-osal-default.yml @@ -8,7 +8,7 @@ jobs: codeql: name: CodeQl Analysis uses: nasa/cFS/.github/workflows/codeql-reusable.yml@main - with: + with: component-path: cFS # Causes reusable workflow to not checkout bundle setup: 'cp Makefile.sample Makefile' prep: 'make prep' diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index ea2250b04..46621746a 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -10,6 +10,6 @@ jobs: static-analysis: name: Run Static Analysis uses: nasa/cFS/.github/workflows/static-analysis.yml@main - with: + with: strict-dir-list: './src/bsp ./src/os' cmake-project-options: -DENABLE_UNIT_TESTS=TRUE -DOSAL_OMIT_DEPRECATED=TRUE -DOSAL_SYSTEM_BSPTYPE=generic-linux diff --git a/src/bsp/pc-rtems/src/bsp_start.c b/src/bsp/pc-rtems/src/bsp_start.c index acdabe2c3..b033c9bb2 100644 --- a/src/bsp/pc-rtems/src/bsp_start.c +++ b/src/bsp/pc-rtems/src/bsp_start.c @@ -77,7 +77,8 @@ void OS_BSP_Setup(void) struct stat statbuf; const char *cmdlinestr; const char *cmdp; - char * cmdi, *cmdo; + char * cmdi; + char * cmdo; cmdlinestr = bsp_cmdline(); diff --git a/src/examples/tasking-example/tasking-example.c b/src/examples/tasking-example/tasking-example.c index 2316e767e..72be37941 100644 --- a/src/examples/tasking-example/tasking-example.c +++ b/src/examples/tasking-example/tasking-example.c @@ -65,8 +65,11 @@ void task_3(void); #define MUTEX_ID 1 -uint32 task_1_id, task_2_id, task_3_id; -uint32 mutex_id, msgq_id; +uint32 task_1_id; +uint32 task_2_id; +uint32 task_3_id; +uint32 mutex_id; +msgq_id msgq_id; /* Global Data */ diff --git a/src/os/posix/src/os-impl-tasks.c b/src/os/posix/src/os-impl-tasks.c index f41428661..4f9d5f108 100644 --- a/src/os/posix/src/os-impl-tasks.c +++ b/src/os/posix/src/os-impl-tasks.c @@ -434,7 +434,7 @@ int32 OS_Posix_TaskAPI_Impl_Init(void) int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, osal_priority_t priority, size_t stacksz, PthreadFuncPtr_t entry, void *entry_arg) { - int return_code = 0; + int return_code; pthread_attr_t custom_attr; struct sched_param priority_holder; diff --git a/src/os/rtems/src/os-impl-loader.c b/src/os/rtems/src/os-impl-loader.c index 2ec9f79b1..bf8b3ea67 100644 --- a/src/os/rtems/src/os-impl-loader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -107,7 +107,7 @@ static bool OS_rtems_rtl_check_unresolved(OSAL_UNRESOLV_REC_TYPE *rec, void *dat *-----------------------------------------------------------------*/ int32 OS_ModuleLoad_Impl(const OS_object_token_t *token, const char *translated_path) { - int32 status = OS_ERROR; + int32 status; int unresolved; void * dl_handle; OS_impl_module_internal_record_t *impl; diff --git a/src/os/shared/src/osapi-common.c b/src/os/shared/src/osapi-common.c index 6e13a7170..a9c5678de 100644 --- a/src/os/shared/src/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -102,7 +102,7 @@ int32 OS_NotifyEvent(OS_Event_t event, osal_id_t object_id, void *data) *-----------------------------------------------------------------*/ int32 OS_API_Init(void) { - int32 return_code = OS_SUCCESS; + int32 return_code; osal_objtype_t idtype; uint32 microSecPerSec; diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index 24645bda2..44a6f7b46 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -616,7 +616,8 @@ int32 OS_ObjectIdFindNextFree(OS_object_token_t *token) for (i = 0; i < max_id; ++i) { - local_id = (++serial) % max_id; + serial++; + local_id = serial % max_id; if (serial >= OS_OBJECT_INDEX_MASK) { /* reset to beginning of ID space */ diff --git a/src/tests/mutex-test/mutex-test.c b/src/tests/mutex-test/mutex-test.c index 30c412415..92b999607 100644 --- a/src/tests/mutex-test/mutex-test.c +++ b/src/tests/mutex-test/mutex-test.c @@ -112,8 +112,7 @@ void task_2(void) while (1) { - status = OS_TaskDelay(200); - + OS_TaskDelay(200); status = OS_MutSemTake(mut_sem_id); if (status != OS_SUCCESS) { @@ -164,7 +163,7 @@ void task_3(void) while (1) { - status = OS_TaskDelay(300); + OS_TaskDelay(300); status = OS_MutSemTake(mut_sem_id); if (status != OS_SUCCESS) { diff --git a/src/tests/queue-test/queue-test.c b/src/tests/queue-test/queue-test.c index 4f8870e1a..1a9a6e12a 100644 --- a/src/tests/queue-test/queue-test.c +++ b/src/tests/queue-test/queue-test.c @@ -194,7 +194,7 @@ void QueueMessageSetup(void) int32 status; uint32 accuracy = 0; int i; - uint32 Data = 0; + uint32 Data; task_1_failures = 0; task_1_messages = 0; task_1_timeouts = 0; @@ -229,7 +229,9 @@ void QueueMessageSetup(void) for (i = 0; i < MSGQ_TOTAL; i++) { if (i > MSGQ_BURST) + { OS_TaskDelay(400); + } Data = i; status = OS_QueuePut(msgq_id, (void *)&Data, sizeof(Data), 0); diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index d8df019ca..51317dd8b 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -130,8 +130,8 @@ void Test_OS_BinSemGetIdByName(void) * int32 OS_BinSemGetIdByName (uint32 *sem_id, const char *sem_name) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + int32 actual; + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_BinSemGetIdByName(&objid, "UT"); @@ -154,7 +154,7 @@ void Test_OS_BinSemGetInfo(void) * int32 OS_BinSemGetInfo (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; OS_bin_sem_prop_t prop; memset(&prop, 0, sizeof(prop)); diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 87d570956..1f17e8d63 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -118,8 +118,8 @@ void Test_OS_CountSemGetIdByName(void) * int32 OS_CountSemGetIdByName (uint32 *sem_id, const char *sem_name) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - osal_id_t objid = OS_OBJECT_ID_UNDEFINED; + int32 actual; + osal_id_t objid = OS_OBJECT_ID_UNDEFINED; UT_SetDefaultReturnValue(UT_KEY(OS_ObjectIdFindByName), OS_SUCCESS); actual = OS_CountSemGetIdByName(&objid, "UT"); @@ -142,7 +142,7 @@ void Test_OS_CountSemGetInfo(void) * int32 OS_CountSemGetInfo (uint32 sem_id, OS_count_sem_prop_t *count_prop) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; OS_count_sem_prop_t prop; memset(&prop, 0, sizeof(prop)); diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index 96bf1eb53..e2f73c567 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -77,8 +77,7 @@ void Test_OS_OpenCreate(void) /* Test failure to convert path */ UT_SetDefaultReturnValue(UT_KEY(OS_TranslatePath), OS_ERROR); - expected = OS_ERROR; - actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); + actual = OS_OpenCreate(&filedes, "/cf/file", OS_FILE_FLAG_NONE, OS_READ_WRITE); UtAssert_True(actual == OS_ERROR, "OS_OpenCreate() (%ld) == OS_ERROR (bad path)", (long)actual); UT_ClearDefaultReturnValue(UT_KEY(OS_TranslatePath)); } diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index 1952788af..bcdd317dc 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -143,7 +143,7 @@ void Test_OS_rmfs(void) * int32 OS_rmfs (const char *devname) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; actual = OS_rmfs("/ramdev5"); UtAssert_True(actual == expected, "OS_rmfs() (%ld) == OS_SUCCESS", (long)actual); @@ -372,7 +372,7 @@ void Test_OS_GetFsInfo(void) * int32 OS_GetFsInfo(OS_FsInfo_t *filesys_info) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; os_fsinfo_t filesys_info; OS_common_record_t rec; @@ -417,7 +417,7 @@ void Test_OS_TranslatePath(void) */ char LocalBuffer[OS_MAX_PATH_LEN]; int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; memset(LocalBuffer, 0, sizeof(LocalBuffer)); diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 053931283..e84463559 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -358,8 +358,8 @@ void Test_OS_GetMaxForObjectType(void) * uint32 OS_GetMaxForObjectType(uint32 idtype); */ osal_objtype_t idtype; - uint32 expected = 0xFFFFFFFF; - uint32 max = 0; + uint32 expected; + uint32 max; for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) { @@ -391,8 +391,8 @@ void Test_OS_GetBaseForObjectType(void) * uint32 OS_GetBaseForObjectType(uint32 idtype); */ osal_objtype_t idtype; - uint32 expected = 0xFFFFFFFF; - uint32 max = 0; + uint32 expected; + uint32 max; for (idtype = 0; idtype < OS_OBJECT_TYPE_USER; ++idtype) { @@ -430,7 +430,7 @@ void Test_OS_ObjectIdToArrayIndex(void) osal_id_t objid; osal_index_t local_idx = OSAL_INDEX_C(0); int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; /* need to get a "valid" objid for the nominal case */ OS_ObjectIdCompose_Impl(OS_OBJECT_TYPE_OS_TASK, 1, &objid); @@ -506,7 +506,7 @@ void Test_OS_ObjectIdGetById(void) * *token); * */ - int32 actual = ~OS_SUCCESS; + int32 actual; int32 expected = OS_SUCCESS; osal_id_t refobjid; osal_index_t local_idx = OSAL_INDEX_C(0); @@ -734,7 +734,7 @@ void Test_OS_ObjectIdAllocateNew(void) * This test case mainly focuses on additional error checking */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; OS_object_token_t token; memset(&token, 0, sizeof(token)); diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index a50c47a90..0c3f82c4c 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -127,7 +127,7 @@ void Test_OS_SymbolLookup(void) * int32 OS_SymbolLookup(cpuaddr *SymbolAddress, const char *SymbolName) */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; cpuaddr testaddr = 0; cpuaddr symaddr = 0; @@ -201,8 +201,8 @@ void Test_OS_StaticSymbolLookup(void) * The ability to get line coverage requires a non-empty lookup table, so one is supplied here. */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; - cpuaddr addr = 0; + int32 actual; + cpuaddr addr = 0; /* nominal */ actual = OS_SymbolLookup_Static(&addr, "UT_staticsym", NULL); @@ -239,7 +239,7 @@ void Test_OS_StaticSymbolLookup(void) void Test_OS_SymbolTableDump(void) { int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; + int32 actual; actual = OS_SymbolTableDump("test", OSAL_SIZE_C(555)); UtAssert_True(actual == expected, "OS_SymbolTableDump() (%ld) == OS_SUCCESS", (long)actual); diff --git a/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c b/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c index 9b22b7188..e1c21f4b3 100644 --- a/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c @@ -67,7 +67,7 @@ void OCS_abort(void) unsigned long int OCS_strtoul(const char *nptr, char **endptr, int base) { int32 Status; - unsigned long Result = 0; + unsigned long Result; Status = UT_DEFAULT_IMPL_RC(OCS_strtoul, -1); diff --git a/src/unit-tests/inc/ut_os_support.h b/src/unit-tests/inc/ut_os_support.h index 82187bcf7..579344475 100644 --- a/src/unit-tests/inc/ut_os_support.h +++ b/src/unit-tests/inc/ut_os_support.h @@ -128,7 +128,9 @@ static inline bool UtOsalImplemented(int32 Fn, const char *File, uint32 Line) { \ int x = snprintf(buf, sizeof(buf), __VA_ARGS__); \ if (x > 0 && x < sizeof(buf)) \ + { \ buf[x] = 0; \ + } \ } while (0) /*--------------------------------------------------------------------------------*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_misc_test.c b/src/unit-tests/oscore-test/ut_oscore_misc_test.c index 00ebc160e..1931a3288 100644 --- a/src/unit-tests/oscore-test/ut_oscore_misc_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_misc_test.c @@ -244,7 +244,7 @@ void UT_os_printfdisable_test() void UT_os_getlocaltime_test() { OS_time_t time_struct; - int32 i = 0; + int32 i; memset(&time_struct, 0, sizeof(time_struct)); @@ -310,7 +310,7 @@ void UT_os_getlocaltime_test() void UT_os_setlocaltime_test() { OS_time_t time_struct; - int32 i = 0; + int32 i; memset(&time_struct, 0, sizeof(time_struct)); diff --git a/src/unit-tests/oscore-test/ut_oscore_queue_test.c b/src/unit-tests/oscore-test/ut_oscore_queue_test.c index 0d858dc66..3ec975043 100644 --- a/src/unit-tests/oscore-test/ut_oscore_queue_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_queue_test.c @@ -69,7 +69,7 @@ **--------------------------------------------------------------------------------*/ void UT_os_queue_create_test() { - int i = 0; + int i; osal_id_t queue_id = OS_OBJECT_ID_UNDEFINED; osal_id_t queue_id2 = OS_OBJECT_ID_UNDEFINED; char queue_name[UT_OS_NAME_BUFF_SIZE]; diff --git a/src/unit-tests/oscore-test/ut_oscore_select_test.c b/src/unit-tests/oscore-test/ut_oscore_select_test.c index 7dbbdae83..588a34831 100644 --- a/src/unit-tests/oscore-test/ut_oscore_select_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_select_test.c @@ -160,7 +160,8 @@ void UT_os_select_single_test(void) **--------------------------------------------------------------------------------*/ void UT_os_select_multi_test(void) { - OS_FdSet ReadSet, WriteSet; + OS_FdSet ReadSet; + OS_FdSet WriteSet; UT_SETUP(OS_SelectFdZero(&WriteSet)); UT_SETUP(OS_SelectFdAdd(&WriteSet, selecttest_fd)); diff --git a/src/unit-tests/oscore-test/ut_oscore_task_test.c b/src/unit-tests/oscore-test/ut_oscore_task_test.c index 71f5369ce..c7fb857d5 100644 --- a/src/unit-tests/oscore-test/ut_oscore_task_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_task_test.c @@ -104,7 +104,7 @@ void generic_test_task(void) **--------------------------------------------------------------------------------*/ void UT_os_task_create_test() { - int32 i = 0; + int32 i; char task_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ diff --git a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c index e11baed56..88d348a25 100644 --- a/src/unit-tests/osfile-test/ut_osfile_fileio_test.c +++ b/src/unit-tests/osfile-test/ut_osfile_fileio_test.c @@ -167,7 +167,8 @@ void UT_os_initfs_test() **--------------------------------------------------------------------------------*/ void UT_os_createfile_test() { - int32 i = 0, j = 0; + int32 i; + int32 j; osal_id_t fd; /*-----------------------------------------------------*/ @@ -304,7 +305,8 @@ void UT_os_createfile_test() **--------------------------------------------------------------------------------*/ void UT_os_openfile_test() { - int32 i = 0, j = 0; + int32 i; + int32 j; osal_id_t fd; /*-----------------------------------------------------*/ @@ -742,7 +744,9 @@ void UT_os_writefile_test() void UT_os_lseekfile_test() { size_t buffLen; - int32 pos1 = 0, pos2 = 0, pos3 = 0; + int32 pos1; + int32 pos2; + int32 pos3; UT_RETVAL(OS_lseek(UT_OBJID_INCORRECT, 0, OS_SEEK_SET), OS_ERR_INVALID_ID); UT_RETVAL(OS_lseek(OS_OBJECT_ID_UNDEFINED, 0, OS_SEEK_SET), OS_ERR_INVALID_ID); diff --git a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c index 36106e888..5c79f7c68 100644 --- a/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c +++ b/src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c @@ -123,8 +123,8 @@ extern char g_mntNames[UT_OS_FILESYS_LIST_LEN][UT_OS_FILE_BUFF_SIZE]; **--------------------------------------------------------------------------------*/ void UT_os_initfs_test() { - int32 i = 0, j = 0; - + int32 i; + int32 j; /*-----------------------------------------------------*/ /* API not implemented */ @@ -238,8 +238,8 @@ void UT_os_initfs_test() **--------------------------------------------------------------------------------*/ void UT_os_makefs_test() { - int32 i = 0, j = 0; - + int32 i; + int32 j; /*-----------------------------------------------------*/ /* API not implemented */ diff --git a/src/unit-tests/ostimer-test/ut_ostimer_test.c b/src/unit-tests/ostimer-test/ut_ostimer_test.c index 0ee3e4f50..793f4a3d7 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_test.c @@ -72,11 +72,13 @@ void UT_os_setup_timerset_test(void); void UT_os_timercallback(osal_id_t timerId) { - int deltaTime = 0; - static int32 loopCnt = 0, res = 0; + int deltaTime; + static int32 loopCnt = 0; + static int32 res = 0; static uint32 prevIntervalTime = 0; static uint32 currIntervalTime = 0; - static OS_time_t currTime = {0}, endTime = {0}; + static OS_time_t currTime = {0}; + static OS_time_t endTime = {0}; if (OS_ObjectIdEqual(timerId, g_timerId)) { @@ -95,12 +97,18 @@ void UT_os_timercallback(osal_id_t timerId) currIntervalTime = OS_TimeGetTotalMicroseconds(OS_TimeSubtract(endTime, currTime)); if (currIntervalTime >= prevIntervalTime) + { deltaTime = currIntervalTime - prevIntervalTime; + } else + { deltaTime = prevIntervalTime - currIntervalTime; + } if ((deltaTime > g_toleranceVal) && (loopCnt > 1)) + { res = -1; + } loopCnt++; currTime = endTime; diff --git a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c index c52c87ac8..02f5f4cf6 100644 --- a/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c +++ b/src/unit-tests/ostimer-test/ut_ostimer_timerio_test.c @@ -170,7 +170,8 @@ void UT_os_reconftimercallback(osal_id_t timerId, void *arg) **--------------------------------------------------------------------------------*/ void UT_os_timercreate_test() { - int32 i = 0, j = 0; + int32 i; + int32 j; char tmpStr[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ @@ -401,7 +402,8 @@ void UT_os_timerdelete_test() **--------------------------------------------------------------------------------*/ void UT_os_timerset_test() { - uint32 startTime = 0, intervalTime = 0; + uint32 startTime; + uint32 intervalTime; /*-----------------------------------------------------*/ /* #1 Invalid-id-arg */ diff --git a/src/ut-stubs/osapi-printf-handlers.c b/src/ut-stubs/osapi-printf-handlers.c index 311544048..f613e4ed8 100644 --- a/src/ut-stubs/osapi-printf-handlers.c +++ b/src/ut-stubs/osapi-printf-handlers.c @@ -39,7 +39,7 @@ void UT_DefaultHandler_OS_printf(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context, va_list va) { const char *string = UT_Hook_GetArgValueByName(Context, "string", const char *); - size_t length = strlen(string); + size_t length; char str[128]; va_list va_debugcopy; int32 status; diff --git a/ut_assert/src/uttools.c b/ut_assert/src/uttools.c index f593c59ab..5a8ce0a8c 100644 --- a/ut_assert/src/uttools.c +++ b/ut_assert/src/uttools.c @@ -55,7 +55,9 @@ bool UtMem2BinFile(const void *Memory, const char *Filename, uint32 Length) { FILE *fp; - if ((fp = fopen(Filename, "w"))) + fp = fopen(Filename, "w"); + + if (fp) { fwrite(Memory, Length, 1, fp); fclose(fp); @@ -97,7 +99,9 @@ bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length) uint32 i; uint32 j; - if ((fp = fopen(Filename, "w"))) + fp = fopen(Filename, "w"); + + if (fp) { for (i = 0; i < Length; i += 16) { @@ -105,15 +109,21 @@ bool UtMem2HexFile(const void *Memory, const char *Filename, uint32 Length) for (j = 0; j < 16; j++) { if ((i + j) < Length) + { fprintf(fp, "%02X ", ((uint8 *)Memory)[i + j]); + } else + { fprintf(fp, " "); + } } fprintf(fp, " "); for (j = 0; j < 16; j++) { if ((i + j) < Length) + { fprintf(fp, "%c", isprint(((uint8 *)Memory)[i + j]) ? ((uint8 *)Memory)[i + j] : '.'); + } } fprintf(fp, "\n"); } @@ -159,7 +169,9 @@ char *UtSprintf(const char *Spec, ...) ++TextIndex; if (TextIndex >= UT_SNPRINTF_MAX_BUFS) + { TextIndex = 0; + } va_start(Args, Spec); vsnprintf(Buf[TextIndex].Text, sizeof(Buf[TextIndex].Text), Spec, Args); @@ -231,7 +243,9 @@ bool UtMem2BinFileCmp(const void *Memory, const char *Filename) uint32 i; Success = true; - if ((fp = fopen(Filename, "r"))) + fp = fopen(Filename, "r"); + + if (fp) { for (i = 0; (FileByte = fgetc(fp)) != EOF; i++) {