coccinelle: generalize pidref_is_set() to =~ _is_set()

Our coccinelle/check-pointer-deref.cocci checker has a special
case for `assert(pidref_is_set(param))`. It turns out we can
generalize this and catch the following:
- iovec_is_set
- sd_dhcp_duid_is_set
- sd_dhcp_client_id_is_set
This commit is contained in:
Michael Vogt
2026-03-27 11:14:49 +01:00
parent be176c0c91
commit bf2d68433d
2 changed files with 7 additions and 5 deletions
+7 -4
View File
@@ -13,6 +13,7 @@
*/
@@
identifier fn, param;
identifier is_set =~ "_is_set$";
type T;
position p;
@@
@@ -25,10 +26,12 @@ fn(..., T *param, ...) {
when != assert_return(param, ...)
when != ASSERT_PTR(param)
when != POINTER_MAY_BE_NULL(param)
/* NULL-safe helpers used commonly enough in assert() to warrant inclusion
* here. For less common cases, use POINTER_MAY_BE_NULL(param) instead of
* extending this list. */
when != assert(pidref_is_set(param))
/* Any foo_is_set(param) guard implies param != NULL, since all *_is_set()
* helpers in systemd return false for NULL input. Note the is_set regex
* in identifier. */
when != assert(is_set(param))
when != assert_return(is_set(param), ...)
when != \( is_set(param) \)
when != \( param == NULL \| param != NULL \| !param \)
* *param@p
...