Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #117, Resolved cppcheck warning #118

Merged
merged 1 commit into from
Dec 30, 2019
Merged

issue #117, Resolved cppcheck warning #118

merged 1 commit into from
Dec 30, 2019

Conversation

avan989
Copy link
Contributor

@avan989 avan989 commented Dec 6, 2019

Describe the contribution
Resolve PSP cpp check warning

Testing performed
Steps taken to test the contribution:

  1. cppcheck --force --inline-suppr --std=c99 --language=c --error-exitcode=1 --enable=warning,performance,portability,style --inconclusive psp/fsw 2>psp.txt

  2. Verify warning is gone

  3. make prep

  4. make

  5. make install

  6. verify cfs still runs.

System(s) tested on:

  • Hardware
  • Ubuntu 18.04
  • CFS 6.6

Contributor Info
Anh Van, NASA Goddard

Copy link
Contributor

@skliper skliper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the requested changes I put in from the issue commit.

@avan989
Copy link
Contributor Author

avan989 commented Dec 6, 2019

Could single line it - what does cppcheck say if you do strncpy(Taskname, "TBD\0", 16)

You get the warning: The buffer 'TaskName' may not be null-terminated after the call to strncpy().
I think you would have to use a different function call (snprintf?) if you want it to be done in one line.

@skliper
Copy link
Contributor

skliper commented Dec 6, 2019

Actually since it's just copying a constant, I'd vote to just strcpy(Taskname, "TBD");. Does that work?

@avan989
Copy link
Contributor Author

avan989 commented Dec 6, 2019

yes. Updated.

@@ -135,7 +135,7 @@ void CFE_PSP_ExceptionHook (int task_id, int vector, int32 *pEsf )
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be strcpy?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is merely a placeholder. The exception processing in PC-RTEMS is not really implemented, and clearly bits and pieces were at one point copied from the vxworks psp.

My suggestion is to remove the entire block from lines 133-150, and just set CFE_PSP_ExceptionReasonString to something like UNIMPLEMENTED.

Note that the test in the if statement on line 140 is totally bogus because TaskName is a local stack array, it can never be NULL.

@@ -677,16 +677,31 @@ int32 CFE_PSP_InitProcessorReservedMemory( uint32 RestartType )
if ( RestartType == CFE_PSP_RST_TYPE_PROCESSOR )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CCB may want these to be OS_DEBUG so it has zero impact on current behavior unless debug is enabled (assuming this passes cppcheck).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding #ifdef OS_DEBUG_PRINTF ... will still cause warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great point, didn't realize OS_DEBUG was a no-op if OS_DEBUG_PRINTF is not defined. How about:

if (result != whatever_the_success_code_is)
  OS_printf("xyz_function didn't return success (%d)\n", return_code);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several complaints about this code - we should clean it up properly rather than just squelching the cppcheck warnings about it. After all, the point of running cppcheck is to actually improve the code, not just to keep the tool quiet.

Two issues:

  1. the calls to the sub-functions are the same, in the same order, just with a different (hard-coded!) parameter, which should be equal to the RestartType value to begin with. So can we just call e.g.

CFE_PSP_InitCDS(RestartType)

and so on, and get rid of the if statement and else branch completely?

  1. Failure of any of these memory initialization routines will almost certainly cause CFE to fail later on. If any failure occurs, it should not just print it, but stop the process and return the value to the caller. Also, the caller should check the value and do a CFE_PSP_Panic() if it fails. Currently it ignores it.

@@ -677,16 +677,31 @@ int32 CFE_PSP_InitProcessorReservedMemory( uint32 RestartType )
if ( RestartType == CFE_PSP_RST_TYPE_PROCESSOR )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have several complaints about this code - we should clean it up properly rather than just squelching the cppcheck warnings about it. After all, the point of running cppcheck is to actually improve the code, not just to keep the tool quiet.

Two issues:

  1. the calls to the sub-functions are the same, in the same order, just with a different (hard-coded!) parameter, which should be equal to the RestartType value to begin with. So can we just call e.g.

CFE_PSP_InitCDS(RestartType)

and so on, and get rid of the if statement and else branch completely?

  1. Failure of any of these memory initialization routines will almost certainly cause CFE to fail later on. If any failure occurs, it should not just print it, but stop the process and return the value to the caller. Also, the caller should check the value and do a CFE_PSP_Panic() if it fails. Currently it ignores it.

@@ -135,7 +135,7 @@ void CFE_PSP_ExceptionHook (int task_id, int vector, int32 *pEsf )
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is merely a placeholder. The exception processing in PC-RTEMS is not really implemented, and clearly bits and pieces were at one point copied from the vxworks psp.

My suggestion is to remove the entire block from lines 133-150, and just set CFE_PSP_ExceptionReasonString to something like UNIMPLEMENTED.

Note that the test in the if statement on line 140 is totally bogus because TaskName is a local stack array, it can never be NULL.

@avan989
Copy link
Contributor Author

avan989 commented Dec 11, 2019

Updated.
cfe_psp_exception.c - removed block of code and replace with "Not Implemented"
cfe_psp_memory.c - Return if error
pc-linux/src/cfe_psp_start.c - check return and call cfe_psp_panic() if failed.

@avan989
Copy link
Contributor Author

avan989 commented Dec 12, 2019

Updated.

@skliper
Copy link
Contributor

skliper commented Dec 18, 2019

CCB 20191218 - Reviewed and approved for IC

@skliper skliper added the CCB:Approved Indicates Approval by CCB label Dec 18, 2019
@skliper skliper changed the base branch from master to merge-20191230 December 30, 2019 22:43
@skliper skliper merged commit 9334835 into nasa:merge-20191230 Dec 30, 2019
skliper added a commit that referenced this pull request Dec 30, 2019
Fix #117, #119
Reviewed and approved at 2019-12-18 CCB
@skliper skliper added this to the 1.5.0 milestone Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CCB:Approved Indicates Approval by CCB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants