diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 7ea028246a2ee..287824984623c 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -547,7 +547,7 @@ class MallocChecker {{CDM::CLibrary, {"strdup"}, 1}, &MallocChecker::checkStrdup}, {{CDM::CLibrary, {"_strdup"}, 1}, &MallocChecker::checkStrdup}, {{CDM::CLibrary, {"kmalloc"}, 2}, &MallocChecker::checkKernelMalloc}, - {{CDM::CLibrary, {"if_nameindex"}, 1}, &MallocChecker::checkIfNameIndex}, + {{CDM::CLibrary, {"if_nameindex"}, 0}, &MallocChecker::checkIfNameIndex}, {{CDM::CLibrary, {"wcsdup"}, 1}, &MallocChecker::checkStrdup}, {{CDM::CLibrary, {"_wcsdup"}, 1}, &MallocChecker::checkStrdup}, {{CDM::CLibrary, {"g_malloc"}, 1}, &MallocChecker::checkBasicAlloc}, diff --git a/clang/test/Analysis/malloc-failure.c b/clang/test/Analysis/malloc-failure.c index bf421fe7672c8..aea58dad470fa 100644 --- a/clang/test/Analysis/malloc-failure.c +++ b/clang/test/Analysis/malloc-failure.c @@ -71,6 +71,6 @@ void test_strdup() { void test_ifnameindex() { struct if_nameindex *p = if_nameindex(); - p->x = 1; //FIXME: if_nameindex is not recognized by the checker + p->x = 1; //expected-warning{{dereference of a null pointer}} if_freenameindex(p); } diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index efb2d52d3a321..20e868b958fda 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -1019,6 +1019,21 @@ void testWinWcsdupContentIsDefined(const wchar_t *s, unsigned validIndex) { free(s2); } +struct if_nameindex { char x; }; +struct if_nameindex *if_nameindex(void); +void if_freenameindex(struct if_nameindex *ptr); + +char testIfnameindex() { + struct if_nameindex *i = if_nameindex(); + return i->x; // expected-warning {{Potential leak of memory pointed to by}} +} + +void testIffreenameindex() { + struct if_nameindex *i = if_nameindex(); + char x = i->x; + if_freenameindex(i); +} // no warning + // ---------------------------------------------------------------------------- // Test the system library functions to which the pointer can escape. // This tests false positive suppression.