Misra-c 10.3 violation with enum boolean only with stub variables
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sandi Southard
am 25 Jan. 2018
Kommentiert: Walter Roberson
am 28 Jan. 2018
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 Kommentar
Walter Roberson
am 25 Jan. 2018
It would probably make more sense if you changed the "This line..." to comments on the appropriate line.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 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 Kommentare
Walter Roberson
am 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?
Siehe auch
Kategorien
Mehr zu Run Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!