You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The loop inside this function has a poorly-constructed condition for ending the loop. It is comparing a uint32 type to an int32 type, and in the event that the MaxNumRegEntries is zero, it becomes impossible for this condition to be true and the loop runs forever.
To Reproduce
Easy to see in unit test if one clears the CFE_ES_Global data structure between tests.
Expected behavior
Loops should never have ending conditions that are impossible to reach unless they are supposed to be infinite. In the event that CFE_ES_Global.CDSVars.MaxNumRegEntries is 0, it should exit immediately.
} while ( (RegIndx==CFE_ES_CDS_NOT_FOUND) && (i< (CFE_ES_Global.CDSVars.MaxNumRegEntries-1)) );
It is generally a bad idea to do any sort of relational comparison (greater than/less than) between signed and unsigned types, C++ actually errors about this but C does not.
System observed on:
Ubuntu 20.04
Additional context
This variable is initialized in FSW from the config CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES which does say that the value needs to be at least 8. But during unit test the value can be zero.
Interestingly, CFE_ES_FindFreeCDSRegistryEntry swaps the weirdly-structured do-while for a normal while loop, so it is OK however it still does a signed/unsigned compare which should be fixed.
Reporter Info
Joseph Hickey, Vantage Systems. Inc.
The text was updated successfully, but these errors were encountered:
The CFE_ES_FindCDSInRegistry function had an unusual loop control
structure with mixed types of signed and unsigned.
This has the possibility of being infinite if the MaxNumRegEntries
is zero due to the way the end condition is structured.
Simplify to be like other loops and use unsigned int control variable.
Describe the bug
The loop inside this function has a poorly-constructed condition for ending the loop. It is comparing a
uint32
type to anint32
type, and in the event that theMaxNumRegEntries
is zero, it becomes impossible for this condition to be true and the loop runs forever.To Reproduce
Easy to see in unit test if one clears the
CFE_ES_Global
data structure between tests.Expected behavior
Loops should never have ending conditions that are impossible to reach unless they are supposed to be infinite. In the event that
CFE_ES_Global.CDSVars.MaxNumRegEntries
is 0, it should exit immediately.Code snips
cFE/fsw/cfe-core/src/es/cfe_es_cds.c
Line 657 in a148b97
It is generally a bad idea to do any sort of relational comparison (greater than/less than) between signed and unsigned types, C++ actually errors about this but C does not.
System observed on:
Ubuntu 20.04
Additional context
This variable is initialized in FSW from the config
CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES
which does say that the value needs to be at least 8. But during unit test the value can be zero.Interestingly,
CFE_ES_FindFreeCDSRegistryEntry
swaps the weirdly-structured do-while for a normal while loop, so it is OK however it still does a signed/unsigned compare which should be fixed.Reporter Info
Joseph Hickey, Vantage Systems. Inc.
The text was updated successfully, but these errors were encountered: