I am using Renesas V850 series microcontroller in my project. My product uses a Non-Volatile memory blocks(NVRam blocks) location which is separate from the main program section. During runtime, these NVRam blocks are monitored to verify that they are not corrupted. This check is done with a code similar to given below:
Logic 1
if((NULL != pBlock_One_Pointer) && (BLOCK_ONE_ID != *(((const tUI8*)pBlock_One_Pointer) + ID_OFFSET)))
{
.....Do some corrective action....
}
The problem with this code is , if pointer "pBlock_One_Pointer" somehow gets corrupted with value "NULL" , the Block_ID check(2nd portion of "if" statement is not done).
One way to avoid this situation is to remove the first part of "if" condition where it checks the Block_ID irrespective of pointer is "NULL" or not as given below
Logic 2
if (BLOCK_ONE_ID != *(((const tUI8*)pBlock_One_Pointer) + ID_OFFSET))
But if "pBlock_One_Pointer" points to NULL, will it cause a exception ?
So basically I have 2 questions:
- Is there a chance that pointer becomes NULL pointer due to some corruption during runtime?
- If so , will Logic 2 help me to overcome it?