Skip to content

Commit

Permalink
Fix nasa#1380, Light coding standards cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Apr 14, 2023
1 parent 88d4b3b commit 618138a
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql-cfe-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion .github/workflows/codeql-osal-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/bsp/pc-rtems/src/bsp_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 5 additions & 2 deletions src/examples/tasking-example/tasking-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
2 changes: 1 addition & 1 deletion src/os/posix/src/os-impl-tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/os/rtems/src/os-impl-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/os/shared/src/osapi-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion src/os/shared/src/osapi-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
5 changes: 2 additions & 3 deletions src/tests/mutex-test/mutex-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
4 changes: 3 additions & 1 deletion src/tests/queue-test/queue-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/unit-test-coverage/shared/src/coveragetest-binsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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));
Expand Down
6 changes: 3 additions & 3 deletions src/unit-test-coverage/shared/src/coveragetest-countsem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/unit-test-coverage/shared/src/coveragetest-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions src/unit-test-coverage/shared/src/coveragetest-filesys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));

Expand Down
14 changes: 7 additions & 7 deletions src/unit-test-coverage/shared/src/coveragetest-idmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions src/unit-test-coverage/shared/src/coveragetest-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/unit-test-coverage/ut-stubs/src/libc-stdlib-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions src/unit-tests/inc/ut_os_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

/*--------------------------------------------------------------------------------*/
Expand Down
4 changes: 2 additions & 2 deletions src/unit-tests/oscore-test/ut_oscore_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/oscore-test/ut_oscore_queue_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion src/unit-tests/oscore-test/ut_oscore_select_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/unit-tests/oscore-test/ut_oscore_task_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

/*-----------------------------------------------------*/
Expand Down
10 changes: 7 additions & 3 deletions src/unit-tests/osfile-test/ut_osfile_fileio_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/*-----------------------------------------------------*/
Expand Down Expand Up @@ -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;

/*-----------------------------------------------------*/
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/unit-tests/osfilesys-test/ut_osfilesys_diskio_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 */

Expand Down
Loading

0 comments on commit 618138a

Please sign in to comment.