On Fri, 1 Nov 2019, Ondřej Surý wrote:

> Hi,
>
> we changed our allocator (wrapper) function to assert() instead of returning 
> ISC_R_MEMORY.
>
> As you can imagine there’s a lot of checks down the road that needs to be 
> cleaned up,
> so I am looking for a way to detect function that only does:
>
> isc_result_t
> foo(…) {
>
> …
> return (ISC_R_SUCCESS);
> }
>
> it could possibly be:
>
> isc_result_t
> foo(…) {
> …
> return (ISC_R_SUCCESS);
> …
> return (ISC_R_SUCCESS);
> }

This is not possible.  ... describes control-flow paths.  Nothing happens
after a return.  Your attempt above would match functions where all
control-flow paths end with return (ISC_R_SUCCESS);, even if some of those
returns are in if branches.

For the case where ISC_R_SUCCESS is in a variable, you could try:

@@
expression E;
identifier foo;
@@

isc_result_t
foo(...) {
... when any
(
-return (ISC_R_SUCCESS);
+return;
|
E = ISC_R_SUCCESS;
...
(
-return (E);
+return;
|
return (ISC_R_SUCCESS);
)
}

julia


>
> Looking at badcheck.cocci, it looks like I just need a block that would 
> „match“ such functions,
> but I can’t find a solid example on how to write a patch that would express:
>
> Mark functions that just return ISC_R_SUCCESS and nothing else:
>
> Something like this:
>
> @match_rule@
> expression E;
> @@
>
> <+... when != E != ISC_R_SUCCESS;
> return (E);
> ...+>
>
> @depends on match_rule@
> @@
>
> - return(...);
> + return;
>
> But that doesn’t work for me, it matches all return()s.
>
> Thanks,
> Ondrej
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to