SourceRange R = E->getArgumentExpr()->getSourceRange();
BR.EmitBasicReport("Potential unintended use of sizeof() on pointer type",
"Logic",
- "The code calls sizeof() on a malloced pointer type, which always returns the wordsize/8. This can produce an unexpected result if the programmer intended to determine how much memory has been allocated.",
+ "The code calls sizeof() on a pointer type. This can produce an unexpected result.",
E->getLocStart(), &R, 1);
}
}
--- /dev/null
+// RUN: clang-cc -analyze -warn-sizeof-pointer -verify %s
+
+struct s {
+};
+
+int f(struct s *p) {
+ return sizeof(p); // expected-warning{{The code calls sizeof() on a pointer type. This can produce an unexpected result.}}
+}