Skip to content

Commit

Permalink
Fix #1365, assert CFE_RESOURCEID_MAX is a bitmask
Browse files Browse the repository at this point in the history
Add a compile time assert to ensure that this value is
actually a power of two-1.  Notes in the comments that
it serves as both a numeric limit and a mask.
  • Loading branch information
jphickey committed Apr 16, 2021
1 parent e80aae9 commit da86146
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions modules/resourceid/fsw/src/cfe_resourceid_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
#include "cfe_resourceid.h"
#include "cfe_resourceid_basevalue.h"

/*
* The "CFE_RESOURCEID_MAX" limit is used as both a numeric maximum as well
* as a mask to separate the serial number bits from the base value bits.
*
* This sanity checks that the value is one less than a power of two so it
* works as a mask and the logic in this file works as expected.
*/
CompileTimeAssert(((CFE_RESOURCEID_MAX + 1) & CFE_RESOURCEID_MAX) == 0, CFE_RESOURCEID_MAX_BITMASK);

/*********************************************************************/
/*
* CFE_ResourceId_GetBase
Expand Down

0 comments on commit da86146

Please sign in to comment.