How to resolve polyspace MISRA C:2012 D4.14 rule when am passing pointer as parameter to function ?
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
this is my fuction FCM_CopyDTCStatusByDTCNumber (uint32 DTC_Number, uint8* data_ptr) and for this its throwing
MISRA C:2012 D4.14 (Required)
The validity of values received from external sources shall be checked.
Array index is from an unsecure source. Index may be negative or too big
and am checking pointer is not null as
void FCM_CopyDTCStatusByDTCNumber (uint32 DTC_Number, uint8* data_ptr)
{
uint16 DTC_Index;
/* Find the DTC Index */
DTC_Index = FCM_FindDTCIndex(DTC_Number);
/* Loop till the all DTCs */
if (DTC_Index < FCM_MAXNUM_DTCS)
{
if(data_ptr!= NULL_PTR) <------
{
/* Copy the DTC Number to buffer */
*data_ptr++ = (uint8)(FCM_DTCInfo[DTC_Index].Fault_Id >> FCM_SIXTEEN);
*data_ptr++ = (uint8)(FCM_DTCInfo[DTC_Index].Fault_Id >> FCM_EIGHT);
*data_ptr++ = (uint8)(FCM_DTCInfo[DTC_Index].Fault_Id);
}
check the arrow mark IN ABOVE CODE i will resolve pointer is not NULL
0 Commenti
Risposte (1)
Luke Halberstadt
il 26 Dic 2019
Even though you are checking that the input parameter is not NULL, it is still possible for the dereferenced "data_ptr" to traverse beyond the end of the valid allocated memory.
Please note that verifying whether or not you stay within the bounds of the provided memory cannot be checked within "FCM_CopyDTCStatusByDTCNumber" unless broader context is given. This could be in the form of the code that calls this function or you could use external constraints:
As described on the constraint page, you cannot constrain function inputs when using Bug Finder. This means that even after you provide constraints for the memory pointed to by "data_ptr", you will still see 4.14 violations in Bug Finder and will need to justify these via comments.
Code Prover ignores directive 4.14, so it will never show 4.14 violations, but it does check for valid memory access, taking constraints into account.
MISRA Checkers:
Code Prover Run-Time Error Memory Check:
0 Commenti
Vedere anche
Categorie
Scopri di più su Run Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!