Misra-c 10.3 violation with enum boolean only with stub variables

12 views (last 30 days)
I have an embedded system where a variable structure is passed to my program. This underlying code is not available so to initialize these variables I'm using a stub file. I have a header file that is included in the stub (and the code being tested). A small portion of the header is:
I'm using
SOMEDATA.H
typedef enum TAG_BOOLEAN
{
BOOLEAN_FALSE,
BOOLEAN_TRUE
} BOOLEAN;
typedef struct SOME_DATA_GLOBAL_TAG
{
UI_8 FirstMessage [ 8U ] ;
UI_8 AnotherVar;
BOOLEAN EEPROMIsBusy ;
} SOME_DATA_GLOBAL;
typedef struct SOME_DATA_TAG
{
SOME_DATA_GLOBAL Global ;
} SOME_DATA ;
SOMEDATA_STUB.C
#include SOMEDATA.H
volatile SOME_DATA m_Data ;
void Some_InitStubs ( void )
{
m_Data.Global.FirstMessage = 0U;
m_Data.Global.AnotherVar = 0U;
EEPROMIsBusy = BOOLEAN_FALSE; also tried EEPROMIsBusy = (BOOLEAN)BOOLEAN_FALSE;
This line produces a MISRA-C:2012 10.3 violation
}
SOME_DATA * SomeData_GetpData ( void )
{
return & m_Data ;
}
In code under test
TESTCODE.C
#include SOMEDATA.H
void CheckSomeData(void)
{
SOME_DATA * pData ;
BOOLEAN internalBoolean;
pData = SomeData_GetpData();
pData->Global.EEPROMIsBusy = BOOLEAN_TRUE;
This line produces a MISRA-C:2012 10.3 violation
internalBoolean = BOOLEAN_FALSE;
This line does not produce a violation.
}
Bug Finder does not flag any assignment of BOOLEAN_TRUE or BOOLEAN_FALSE as an error except with variables used in a stub. In fact, all enum assignments to stub variables are flagged with a 10.3 violation. None of the other code is flagged even though the enum's are used extensively in the code.
How do I fix this?
  1 Comment
Walter Roberson
Walter Roberson on 25 Jan 2018
It would probably make more sense if you changed the "This line..." to comments on the appropriate line.

Sign in to comment.

Accepted Answer

Sandi Southard
Sandi Southard on 26 Jan 2018
Thanks, I'll do that on future posts. Is there any answer for me?

More Answers (1)

Walter Roberson
Walter Roberson on 26 Jan 2018
The line
EEPROMIsBusy = BOOLEAN_FALSE;
is assigning to a variable that has no type declaration in scope, so if it were permitted at all it would be an implicit int and int has a different essential type than enum does.
  2 Comments
Sandi Southard
Sandi Southard on 28 Jan 2018
Sorry, I must have made a mistake in the original post. in SOMEDATA_STUB.C the line should read: m_DATA.Global.EEPROMIsBusy = BOOLEAN_FALSE;
This variable is in scope with a typedef of BOOLEAN.
I still don't understand why only variables of type ENUM that are defined within the stub have violations.
Walter Roberson
Walter Roberson on 28 Jan 2018
https://www.misra.org.uk/forum/viewtopic.php?t=1091 has a relevant discussion.
I would need to look it over more closely but at the moment it seems like it might be implying that the storage type of an enumeration value might be narrower than the type of an enumeration constant, which sounds a bit odd to me. Please read it over and see if you conclude the same thing: if the smallest type can be used for storage but enumeration constants are int then doesn't that imply that the constant could be wider than the destination?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!