Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Yudi Yang <jy103@rice.edu>
Cc: cocci@inria.fr
Subject: Re: [cocci] Match and print size of allocation
Date: Sat, 15 Apr 2023 07:42:57 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2304150740450.2975@hadrien> (raw)
In-Reply-To: <bea8e057-44b0-4ae4-a6cc-b23bd0837270@Spark>

[-- Attachment #1: Type: text/plain, Size: 854 bytes --]



On Fri, 14 Apr 2023, Yudi Yang wrote:

> Hello,
>
> I would like to match the size of allocation, I am wondering if I write the following:
>
> @print@
> expression N, SIZE;
> @@
>
> (
>   malloc(SIZE);

Code doesn't usually contain just malloc(...); because then the return
value would be thrown away.  You can write x = malloc(SIZE); for an
expression metavariable x.  If malloc can be used in other contexts, eg an
if header, then you can write malloc(SIZE)@S where S is a statement
metavariable.  I think that that will allow the printf to be added after
the innermost statement containing the call to malloc.

julia

> |
>   calloc(N, SIZE);
> )
> + printf(“Allocation: %d\n", (N) * (SIZE));
>
> I am not sure if I could set the default value for N in the malloc case, or is there anything I should do to make it correct.
>
> Best, Yudi
>
>
>

  parent reply	other threads:[~2023-04-15  5:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <eccc2924-6657-4776-84f1-3d8413904cf2@Spark>
2023-04-14 22:36 ` [cocci] Match and print size of allocation Yudi Yang
2023-04-15  5:40   ` Julia Lawall
2023-04-15  5:42   ` Julia Lawall [this message]
2023-04-15  6:13 Yudi Yang
2023-04-15  7:31 ` Julia Lawall
2023-04-15 16:40   ` Yudi Yang
2023-04-15 16:53     ` Julia Lawall
2023-04-17 17:48       ` Yudi Yang
     [not found]         ` <alpine.DEB.2.22.394.2304172139580.2883@hadrien>
2023-04-17 23:26           ` Yudi Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.22.394.2304150740450.2975@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=cocci@inria.fr \
    --cc=jy103@rice.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).