[clang] [clang][analyzer] Fixed 'if_nameindex' in MallocChecker (PR #207726)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 6 05:56:55 PDT 2026
https://github.com/balazske created https://github.com/llvm/llvm-project/pull/207726
The function `if_nameindex` has 0 arguments but `MallocChecker` expected it to have 1 argument and was not recognized by the checker correctly.
>From b03f07efa5f6e9cb5f1c208da5732af011aca79c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <balazs.keri at ericsson.com>
Date: Mon, 6 Jul 2026 14:52:49 +0200
Subject: [PATCH] [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);
}
More information about the cfe-commits
mailing list