Re: [cocci] Searching for duplicate exception handling code with SmPL?

Julia Lawall <[email protected]> Sun, 14 Jun 2026 20:44:56 +0200 (CEST)
Newsgroups fr.inria.cocci
Message-ID <[email protected]>
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--8323329-491201442-1781462697=:99844
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8BIT



On Sun, 14 Jun 2026, Markus Elfring wrote:

> >> Do you know any other source file examples already which would also show
> >> the application of goto chains nicely?
> >> https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/recommendations/memory-management-mem/mem12-c/
> > No.  Take the source code in your example and remove lines one by one
> > until you obtain a small function that still illustrates the problem.
>
> Would you find another source file example (like the following) more inspiring?
>
>
> int my_test(void)
> {
>  struct my_data * md1 = kzalloc_obj(*md1);
>
>  if (!md1)
>     return -ENOMEM;
>
>  struct my_data * md2;
>  int rc = make_copy(md1, &md2);
>  if (rc)
>  {
>     kfree(md1);
>     return rc;
>  }
> // placeholder for other control flow
>  if (1)
>  {
>     goto free_object;
>  }
> // placeholder for other control flow
>  if (2)
>  {
>     goto release;
>  }
> // placeholder for other control flow
>  if (3)
>  {
>     goto cleanup;
>  }
> cleanup:
>  my_cleanup();
> release:
>  my_release();
> free_object:
>  kfree(my_object);
>  kfree(md1);
>  return rc;
> }
>
>
>
> Questionable test result:
> Markus_Elfring@Sonne:…/Projekte/Coccinelle/Probe> time /usr/bin/spatch ../janitor/list_selected_duplicate_statements_in_if_branches3.cocci test-insufficient_goto_chain_usage.c
> …
> info|my_test|md1|rc
> first|test-insufficient_goto_chain_usage.c|12|5
> tail|test-insufficient_goto_chain_usage.c|36|2
> info|my_test|md1|rc
> first|test-insufficient_goto_chain_usage.c|36|2
> tail|test-insufficient_goto_chain_usage.c|36|2

Could you please explain what the output actually means?

>
> real    0m0,288s
> user    0m0,197s
> sys     0m0,090s

And don't include this information.  It's not relevant to the question at
hand.

julia

>
> Are going to try such a test case out also on your development system?
>
> How will the clarification evolve further?
>
> Regards,
> Markus
>
--8323329-491201442-1781462697=:99844--