Skip to content

Commit

Permalink
Fix nasa#1258, Return char * from OS_StatusToString
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jun 6, 2022
1 parent bc420d9 commit d902e37
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/os/inc/osapi-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name);
*
* @return Passed in string pointer
*/
os_status_string_t *OS_StatusToString(osal_status_t status, os_status_string_t *status_string);
char *OS_StatusToString(osal_status_t status, os_status_string_t *status_string);
/**@}*/

#endif /* OSAPI_ERROR_H */
7 changes: 5 additions & 2 deletions src/os/shared/src/osapi-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,16 @@ static const OS_ErrorTable_Entry_t OS_GLOBAL_ERROR_NAME_TABLE[] = {
* See description in API and header file for detail
*
*-----------------------------------------------------------------*/
os_status_string_t *OS_StatusToString(osal_status_t status, os_status_string_t *status_string)
char *OS_StatusToString(osal_status_t status, os_status_string_t *status_string)
{
char *string = NULL;

if (status_string != NULL)
{
snprintf(*status_string, sizeof(*status_string), "%ld", OS_StatusToInteger(status));
string = *status_string;
}
return status_string;
return string;
}

/*----------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/unit-test-coverage/shared/src/coveragetest-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ void Test_OS_GetErrorName(void)
**--------------------------------------------------------------------------------*/
void Test_OS_StatusToString_Helper(osal_status_t status)
{
os_status_string_t status_string;
os_status_string_t *rtn_addr;
char expected[OS_STATUS_STRING_LENGTH + 1];
os_status_string_t status_string;
char * rtn_addr;
char expected[OS_STATUS_STRING_LENGTH + 1];

/* Used oversized string to test for truncation */
snprintf(expected, sizeof(expected), "%ld", OS_StatusToInteger(status));
rtn_addr = OS_StatusToString(status, &status_string);
UtAssert_ADDRESS_EQ(rtn_addr, &status_string);
UtAssert_ADDRESS_EQ(rtn_addr, status_string);
UtAssert_STRINGBUF_EQ(status_string, sizeof(status_string), expected, sizeof(expected));
}

Expand Down
8 changes: 4 additions & 4 deletions src/unit-tests/oscore-test/ut_oscore_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,14 +414,14 @@ void UT_os_geterrorname_test(void)
**--------------------------------------------------------------------------------*/
void UT_os_statustostring_test_helper(osal_status_t status)
{
os_status_string_t status_string;
os_status_string_t *rtn_addr;
char expected[OS_STATUS_STRING_LENGTH + 1];
os_status_string_t status_string;
char * rtn_addr;
char expected[OS_STATUS_STRING_LENGTH + 1];

/* Used oversized string to test for truncation */
snprintf(expected, sizeof(expected) - 1, "%ld", OS_StatusToInteger(status));
rtn_addr = OS_StatusToString(status, &status_string);
UtAssert_ADDRESS_EQ(rtn_addr, &status_string);
UtAssert_ADDRESS_EQ(rtn_addr, status_string);
UtAssert_STRINGBUF_EQ(status_string, sizeof(status_string), expected, sizeof(expected));
}

Expand Down
6 changes: 3 additions & 3 deletions src/ut-stubs/osapi-error-stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ int32 OS_GetErrorName(int32 error_num, os_err_name_t *err_name)
* Generated stub function for OS_StatusToString()
* ----------------------------------------------------
*/
os_status_string_t *OS_StatusToString(osal_status_t status, os_status_string_t *status_string)
char *OS_StatusToString(osal_status_t status, os_status_string_t *status_string)
{
UT_GenStub_SetupReturnBuffer(OS_StatusToString, os_status_string_t *);
UT_GenStub_SetupReturnBuffer(OS_StatusToString, char *);

UT_GenStub_AddParam(OS_StatusToString, osal_status_t, status);
UT_GenStub_AddParam(OS_StatusToString, os_status_string_t *, status_string);

UT_GenStub_Execute(OS_StatusToString, Basic, NULL);

return UT_GenStub_GetReturnValue(OS_StatusToString, os_status_string_t *);
return UT_GenStub_GetReturnValue(OS_StatusToString, char *);
}

0 comments on commit d902e37

Please sign in to comment.