sorry for late reply. Sometimes people do use sizeof(pointer) by intention. So we can't warn whenever there is sizeof(pointer) we only try to detect when you do it by mistake.
In your code example I don't think it looks like a mistake.
We should warn in such cases:
memset(pJunk, 0, sizeof(pJunk));
or :
p = (abc *)malloc(sizeof(abc *));
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The documentation says it should check for "using sizeof(pointer) instead of the size of pointed data", so why doesn't this code get flagged?
int main(void)
{
char junk;
char * pJunk = &junk;
unsigned long i;
}
I used: cppcheck --enable=all test.c
(using cppcheck 1.83)
sorry for late reply. Sometimes people do use
sizeof(pointer)
by intention. So we can't warn whenever there issizeof(pointer)
we only try to detect when you do it by mistake.In your code example I don't think it looks like a mistake.
We should warn in such cases:
or :