https://github.com/balazske updated https://github.com/llvm/llvm-project/pull/207726
From b03f07efa5f6e9cb5f1c208da5732af011aca79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <[email protected]> Date: Mon, 6 Jul 2026 14:52:49 +0200 Subject: [PATCH 1/2] [clang][analyzer] Fixed 'if_nameindex' in MallocChecker The function 'if_nameindex' has 0 arguments but MallocChecker expected it to have 1 argument and was not recognized by the checker correctly. --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 2 +- clang/test/Analysis/malloc-failure.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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); } From fb2d5688677c14800869a6a55f826ea8653eb1a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <[email protected]> Date: Thu, 9 Jul 2026 09:55:51 +0200 Subject: [PATCH 2/2] added if_nameindex leak test --- clang/test/Analysis/malloc.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c index efb2d52d3a321..a2e0570f2dcb9 100644 --- a/clang/test/Analysis/malloc.c +++ b/clang/test/Analysis/malloc.c @@ -1019,6 +1019,20 @@ 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(); + if_freenameindex(i); +} // no warning + // ---------------------------------------------------------------------------- // Test the system library functions to which the pointer can escape. // This tests false positive suppression. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
