Reputation: 11
In our project, ASSERT is defined:
#define ASSERT(condition, severity) bsp_assert(condition, severity)
Then in bsp_assert:
void bsp_assert(uint8_t condition, uint8_t severity)
{
if(severity == SEVERITY_HIGH)
{
ll_sys_assert(condition);
}
}
When we run Coverity analysis with agression High, we got thousands of errors related to this assert, like this:
2. var_compare_op Comparing ptr_chnl_clsfction to null implies that ptr_chnl_clsfction might be null.
ASSERT(NULL != ptr_chnl_clsfction , SEVERITY_HIGH);
CID 442026: (#1 of 1): Dereference after null check (FORWARD_NULL)
5. var_deref_op Dereferencing null pointer ptr_chnl_clsfction.
ptr_chnl_clsfction[byte_iter] = 0x00;
I tried to comment bsp_assert, like this:
#define ASSERT(condition, severity) /*We don't use assert*/
Now I don't have any more the issue, but I guess it's not the purpose of assert.
How can I get rid of this issue ?
Thanks.
Upvotes: 1
Views: 210
Reputation: 802
THis is how FORWARD_NULL
is reported in Coveritys:
In Coverity, FORWARD_NULL reports defects when there are enough evidences to be sure the null access will (can) happen.
first, a null assignment, or a comparison with null will give Coverity an evidence to believe the variable could be null.
second, a de-reference of that variable.
When above 2 events happen in the same analysis path, then Coverity will report FORWARD_NULL on the second event
If ptr_chnl_clsfction
is NULL
Dereferencing will result in crash
ptr_chnl_clsfction[byte_iter] = 0x00
Upvotes: 1