Misra-c 10.3 violation with enum boolean only with stub variables
조회 수: 15 (최근 30일)
이전 댓글 표시
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
Walter Roberson
2018년 1월 25일
It would probably make more sense if you changed the "This line..." to comments on the appropriate line.
채택된 답변
추가 답변 (1개)
Walter Roberson
2018년 1월 26일
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
Walter Roberson
2018년 1월 28일
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Run Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!