Hi, 

From what I’ve read, I understand attributes are not supported by coccinelle.
But I’m still wondering it there would be a way to perform a task I’d like to 
do: Checking whether functions marked as returning non-null are used in any 
place so that return value is checked for nullness/nonnullness.
So, this breaks into 2 subproblems:

1) Matching desired functions.

I know I can’t directly match functions having certain attributes.
But we don’t use attributes directly. We use some macros for that.
So, all functions I’d like to pick include the macro FUNC_ATTR_NONNULL_RET in 
their declaration/definition.
Then, would there be any way to match functions having the literal 
“FUNC_ATTR_NONNULL_RET” in their declaration/definition?

2) Applying some rules for the same set of functions.

Up until now, I’ve done this by manually obtaining the list of desired 
functions, and then running this spatch:

```
@@ identifier func =~ 
"^(transstr|list_alloc|listitem_alloc|dict_alloc|dictitem_alloc|dictitem_copy|vim_strsave_fnameescape|ga_concat_strings|enc_canonize|reverse_text|get_tv_string|get_tv_string_buf|viminfo_readstring|ga_concat_strings_sep|xmalloc|xcalloc|xrealloc|xmallocz|xmemdupz|xstrchrnul|xmemscan|xstpcpy|xstpncpy|xstrdup|xstrndup|xmemdup|msg_show_console_dialog|home_replace_save|get_register|invocation_path_tail|concat_fnames|save_absolute_path|getroom|vim_strsave|vim_strnsave|vim_strsave_escaped|vim_strsave_escaped_ext|vim_strsave_shellescape|vim_strsave_up|vim_strnsave_up|strup_save|concat_str)$";
 statement S; @@

(
* if (func(...) == NULL) S;
|
* if (func(...) != NULL) S;
)

@@ identifier func =~ 
"^(transstr|list_alloc|listitem_alloc|dict_alloc|dictitem_alloc|dictitem_copy|vim_strsave_fnameescape|ga_concat_strings|enc_canonize|reverse_text|get_tv_string|get_tv_string_buf|viminfo_readstring|ga_concat_strings_sep|xmalloc|xcalloc|xrealloc|xmallocz|xmemdupz|xstrchrnul|xmemscan|xstpcpy|xstpncpy|xstrdup|xstrndup|xmemdup|msg_show_console_dialog|home_replace_save|get_register|invocation_path_tail|concat_fnames|save_absolute_path|getroom|vim_strsave|vim_strnsave|vim_strsave_escaped|vim_strsave_escaped_ext|vim_strsave_shellescape|vim_strsave_up|vim_strnsave_up|strup_save|concat_str)$";
 identifier var; statement S; expression E; @@

  var = func(...);
  ... when != var = E
(
* if (var == NULL) S;
|
* if (var != NULL) S;
)
```

As you see, I have to replicate the list. Is there any better way to achieve 
the same effect?

Thanks in advance.
Eliseo.

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to