I in fact get the warning twice. I've marked it in the source code below.
For completeness sake, here is the complete routine. It's used for authenticating SMTP connections.
That parameter is a scalar value (the byte value with which to fill the array), but NULL should be used only in a pointer context. Now often C compilers define NULL as simply 0 but it is a misleading use of NULL -- using nullptr in C++11 would find this and produce a compile error instead of accepting it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have the following code:
I get a redundantCopy warning on the line with the memset.
Why is that?
Last edit: Sander Bouwhuis 2015-05-27
I've wrapped your example into an executable scope (to avoid problems with otherwise invalid code snippet)
and ran cppcheck.1.69 a.cpp --enable=all but don't see your error message.
What version do you use?
I use v1.69.
I in fact get the warning twice. I've marked it in the source code below.
For completeness sake, here is the complete routine. It's used for authenticating SMTP connections.
Ok, I fixed it like this:
Last edit: Sander Bouwhuis 2015-05-29
Also I would suggest not to use
NULL
as the second argument tomemset()
.That parameter is a scalar value (the byte value with which to fill the array), but NULL should be used only in a pointer context. Now often C compilers define NULL as simply
0
but it is a misleading use of NULL -- usingnullptr
in C++11 would find this and produce a compile error instead of accepting it.