Hi all,
I think there is a problem with Misra Add-on and rule 13.5: "Rule 13.5 The right hand operand of a logical && or || operator shall not contain persistent side effects"
My code sample:
#defineFORCE_LOG_TIMEOUT60U
#defineLOW_LEVEL_FREE_SPACE1000U
#defineVERY_LOW_LEVEL_FREE_SPACE50Uexternunsignedintu32LastTimeForceLogSpaceLowLevel;externunsignedcharbMaster;externunsignedintTaskLog_u32GetFreeSpace(void);externunsignedintHAL_GetTick(void);staticunsignedcharbForceLogLowLevel(void)
{
unsignedcharbReturn=0u;if(bMaster!=0u)
{
u32LastTimeForceLogSpaceLowLevel=HAL_GetTick();
}
else
{
u32LastTimeForceLogSpaceLowLevel=0xFFFFFFFFU;
}
if((unsignedint)(HAL_GetTick()-u32LastTimeForceLogSpaceLowLevel)<FORCE_LOG_TIMEOUT)
{
bReturn=1u;
}
returnbReturn;
}
unsignedintPushLogData(void)
{
unsignedintu32SDCardFreeSpace=TaskLog_u32GetFreeSpace();if((u32SDCardFreeSpace>LOW_LEVEL_FREE_SPACE)||((u32SDCardFreeSpace>VERY_LOW_LEVEL_FREE_SPACE)&&(bForceLogLowLevel()==1u))/* This violate 13.5 MISRA C:2012 rule*/)/* bForceLogLowLevel function has persistent */
{ /* side effect, because it modifies a global variable */return(u32SDCardFreeSpace*10u); /* u32LastTimeForceLogSpaceLowLevel */
}
return0u;
}
As you can see , a small function PushLogData contains an if statement.
This if statement contains a right hand operand which call a function bForceLogLowLevel. This function modifies a global variable u32LastTimeForceLogSpaceLowLevel. This is considered has a persistent side effect (modify object).
When i look at misra python script rules 13.5, it calls hasSideEffectsRecursive.
In this "function" there is a: # Todo: Check function calls
So i don't know if this rules (13.5) is really available, because side effects will occurs in functions call.
Next thing i use release cppcheck 2.2 without any modification and with above code, the add-on doesn't indicate any failure.
Thanks !
Last edit: Jean-Loic MARTIN 2020-12-04
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Daniel,
Thanks for your quick answer !
Unfortunately, i'm clearly not an expert in Python and can't help for this. So i will wait.
Regarding this rules, verifying that a function doesn't have any side effect seems very difficult to do !
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Regarding this rules, verifying that a function doesn't have any side effect seems very difficult to do !
This is a difficult problem. When we run the addon, we only have access to one Cppcheck dump file. This means that we can only analyze functions defined in the current file.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
that is out of scope for this check imho. if the function body is not seen in the dump file we cannot analyze it and then we fallback and assume it has side effects.
Last edit: Daniel Marjamäki 2020-12-05
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all,
I think there is a problem with Misra Add-on and rule 13.5:
"Rule 13.5 The right hand operand of a logical && or || operator shall not contain persistent side effects"
My code sample:
As you can see , a small function PushLogData contains an if statement.
This if statement contains a right hand operand which call a function bForceLogLowLevel. This function modifies a global variable u32LastTimeForceLogSpaceLowLevel. This is considered has a persistent side effect (modify object).
When i look at misra python script rules 13.5, it calls hasSideEffectsRecursive.
In this "function" there is a: # Todo: Check function calls
So i don't know if this rules (13.5) is really available, because side effects will occurs in functions call.
Next thing i use release cppcheck 2.2 without any modification and with above code, the add-on doesn't indicate any failure.
Thanks !
Last edit: Jean-Loic MARTIN 2020-12-04
hmm.. yes we should not claim that 13.5 is completed yet.
Hi Daniel,
Thanks for your quick answer !
Unfortunately, i'm clearly not an expert in Python and can't help for this. So i will wait.
Regarding this rules, verifying that a function doesn't have any side effect seems very difficult to do !
Well in this case.. I think we should at least make some limited analysis and if we are uncertain after that then assume there is side effects.
To definitely determine if arbitrary function calls have side effects ; that would be extremely difficult.
This is a difficult problem. When we run the addon, we only have access to one Cppcheck dump file. This means that we can only analyze functions defined in the current file.
that is out of scope for this check imho. if the function body is not seen in the dump file we cannot analyze it and then we fallback and assume it has side effects.
Last edit: Daniel Marjamäki 2020-12-05