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

Alternate condition impossible to exercise - static analysis #1180

Closed
skliper opened this issue Feb 26, 2021 · 0 comments · Fixed by #1237 or #1258
Closed

Alternate condition impossible to exercise - static analysis #1180

skliper opened this issue Feb 26, 2021 · 0 comments · Fixed by #1237 or #1258
Milestone

Comments

@skliper
Copy link
Contributor

skliper commented Feb 26, 2021

Is your feature request related to a problem? Please describe.
Impossible to hit alternate case (even considering reconfiguration):

Status is always >= CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE (line 162) since it's checked at line 150:

do
{
/* Allocate memory for shared load buffers */
Status = CFE_ES_GetPoolBuf(&CFE_TBL_Global.LoadBuffs[j].BufferPtr,
CFE_TBL_Global.Buf.PoolHdl,
CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE);
if (Status < CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE)
{
return Status;
}
else
{
/* The buffer is successfully created, so allow it to be used */
CFE_TBL_Global.LoadBuffs[j].Taken = false;
}
j++;
} while ((j < CFE_PLATFORM_TBL_MAX_SIMULTANEOUS_LOADS) &&
(Status >= CFE_PLATFORM_TBL_MAX_SNGL_TABLE_SIZE));
}

NumBlockSizes > CFE_PLATFORM_ES_POOL_MAX_BUCKETS is always false on line 203 since it's checked on 190:

/* If too many sizes are specified, return an error */
if (NumBlockSizes > CFE_PLATFORM_ES_POOL_MAX_BUCKETS)
{
CFE_ES_WriteToSysLog("CFE_ES:poolCreate Num Block Sizes (%d) greater than max (%d)\n",
(int)NumBlockSizes, CFE_PLATFORM_ES_POOL_MAX_BUCKETS);
return(CFE_ES_BAD_ARGUMENT);
}
/*
* Use default block sizes if not specified
*/
if (BlockSizes == NULL)
{
BlockSizes = CFE_ES_MemPoolDefSize;
if (NumBlockSizes == 0 || NumBlockSizes > CFE_PLATFORM_ES_POOL_MAX_BUCKETS)
{
NumBlockSizes = CFE_PLATFORM_ES_POOL_MAX_BUCKETS;
}
}

EventID can never be 0 and RegName can never be NULL, if it was it would be a bug. This sort of thing (preventing a developer from introducing a bug with logic in production code) is better prevented via good unit test design. If a case is added it should check the event.

if (EventID != 0 && ReqName != NULL)

Describe the solution you'd like
Remove cases where an alternate condition can not be exercised

  • A step closer to being able to do MC/DC coverage
  • Remove unnecessary logic

Describe alternatives you've considered
Occasionally considered "future proofing" but developers should never depend on a condition being tested twice when modifying code.

Additional context
Triggers CodeQL warning

Requester Info
Jacob Hageman - NASA/GSFC

@skliper skliper added this to the 7.0.0 milestone Feb 26, 2021
skliper added a commit to skliper/cFE that referenced this issue Mar 17, 2021
skliper added a commit to skliper/cFE that referenced this issue Mar 17, 2021
skliper added a commit to skliper/cFE that referenced this issue Mar 17, 2021
skliper added a commit to skliper/cFE that referenced this issue Mar 23, 2021
astrogeco added a commit that referenced this issue Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant