http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54381
Bug #: 54381
Summary: -Wsizeof-pointer-memaccess refers to "destination" for
strncmp
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: [email protected]
ReportedBy: [email protected]
In this example
#include <string.h>
int f(const char *s) {
const char *t = "a string";
return strncmp(t,s,sizeof t);
}
-Wsizeof-pointer-memaccess nicely detects that sizeof probably is
not what the programmer meant.
x.c: In function ‘f’:
x.c:6:29: warning: argument to ‘sizeof’ in ‘strncmp’ call is the same
expression as the destination; did you mean to provide an explicit
length?[-Wsizeof-pointer-memaccess]
return strncmp(t,s,sizeof t);
^
However, t is not really a "destination". The first two parameters
of strcmp and strncmp both are sources.