I am cleaning up some code from a Coverity issue and have a situation where a pointer local to a function is used earlier on is a function for comparison, then later on it is assigned to point else where but it is never de-referenced or used to assign something to its value. Coverity is saying that it is an unused pointer value - so I am thinking to cast it to a void to indicate the pointer is not used after that point. I am wondering when is a value or variable considered used in a program? Here is a code sample explaining my situation:
In the sample below Coverity would flag the fltr_ptr as not being used after its two assignments at the end of the sample
int initialise (void)
{
// pointer first decalred and defined
FILTER_PTR fltr_ptr = NULL;
// pointer given valid value
fltr_ptr = global_val->filter_group[index];
// second use of fltr_ptr
if ( TRUE == fltr_ptr -> being_used)
{
// first use of fltr_ptr
if ( TRUE != close_filter ( fltr_ptr -> Filter)
{
// print error
}
// do more code
// fltr_ptr assigned first time , value not used should it be (void)fltr_ptr?
fltr_ptr = Free_Memory (fltr_ptr, sizeof(FILTER_PTR));
}
else
{
return 1;
}
for ( number of iterations )
{
// fltr_ptr assigned again but value not used should it be (void)fltr_ptr?
fltr_ptr = global_val->filter_group[index];
}
return 0;
}