What does a single pointer mean in terms of C?
In this case, I think Coverity refers to the difference between a char * array and a pointer to a single char* created using the address of this array.
Coverity warns you that by passing the address of the first buf element to func , you are making it difficult for yourself to safely write to this array because you cannot easily determine its size.
It's hard to be sure without seeing all of your code, but assuming buf is an array that you specified somewhere in your top-level function, and then using sizeof on buf from that function, you get the size of the array.
However, when you pass the buf address to func on the line
func(&inbuf);
... func just gets a pointer to the first element of this array. From func you can no longer use sizeof to determine the size of the array — it simply returns the size of the pointer — and you cannot safely write to this pointer without any implicit understanding of how much space is in the array.
This makes fragile code, and therefore this is bad practice.
(None of this is related to the Singleton Pattern )
razlebe
source share