[clang] [clang][analyzer] Fixed 'if_nameindex' in MallocChecker (PR #207726)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 6 05:58:03 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Balázs Kéri (balazske)
<details>
<summary>Changes</summary>
The function `if_nameindex` has 0 arguments but `MallocChecker` expected it to have 1 argument and was not recognized by the checker correctly.
---
Full diff: https://github.com/llvm/llvm-project/pull/207726.diff
2 Files Affected:
- (modified) clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp (+1-1)
- (modified) clang/test/Analysis/malloc-failure.c (+1-1)
``````````diff
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);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/207726
More information about the cfe-commits
mailing list