Match and print size of allocation
Hello Julia,
Thank you for your answer! I have modified my code:
@@
expression E, SIZE, N;
statement S;
@@
(
E = malloc(SIZE);
+ printf("%d", SIZE);
|
E = calloc(N, SIZE);
+ printf("%d", (N) * (SIZE));
)
However, it cannot match initializations and if-statements. I am not quite understanding your "malloc(SIZE)@S" solution. Could you point on how to use the it, or perhaps some related links?
Thank you,
Yudi
Quoted 36 lines · Julia Lawall
Quoted 10 lines · Yudi Yang
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
Quoted 10 lines
|
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
Quoted 16 lines · Yudi Yang
Hello Julia,
Thank you for your answer! I have modified my code:
@@
expression E, SIZE, N;
statement S;
@@
(
E = malloc(SIZE);
+printf("%d", SIZE);
|
E =calloc(N, SIZE);
+printf("%d", (N) * (SIZE));
)
Quoted 3 lines
However, it cannot match initializations and if-statements. I am not quite understanding your "malloc(SIZE)@S" solution. Could you point on how to use the it, or perhaps some related links?
What I proposed didn't work, but the following works fine:
@@
statement S;
expression size;
@@
(
S
+printf("%d\n",size);
&
malloc(size)
)
julia
Thank you. It now matches if-statements. However, in case of a variable initializer such as:
void* p = malloc(100);
The solution does not correctly recognize the allocation.
Best,
Yudi
Quoted 39 lines · 在 2023年4月15日 -0500 02:31,Julia Lawall <[email protected]>,写道:
Quoted 16 lines · Yudi Yang
Hello Julia,
Thank you for your answer! I have modified my code:
@@
expression E, SIZE, N;
statement S;
@@
(
E = malloc(SIZE);
+printf("%d", SIZE);
|
E =calloc(N, SIZE);
+printf("%d", (N) * (SIZE));
)Quoted 3 lines
However, it cannot match initializations and if-statements. I am not quite understanding your "malloc(SIZE)@S" solution. Could you point on how to use the it, or perhaps some related links?
What I proposed didn't work, but the following works fine:
@@
statement S;
expression size;
@@(
S
+printf("%d\n",size);
&
malloc(size)
)julia
Quoted 5 lines · Yudi Yang
Thank you. It now matches if-statements. However, in case of a variable initializer such as:
void* p = malloc(100);
The solution does not correctly recognize the allocation.
You should be able to use the same idea, except put D, declared as
declaration D;
julia
Quoted 47 lines
Best, Yudi
在 2023年4月15日 -0500 02:31,Julia Lawall <[email protected]>,写道:
On Sat, 15 Apr 2023, Yudi Yang wrote: Hello Julia, Thank you for your answer! I have modified my code: @@ expression E, SIZE, N; statement S; @@ ( E = malloc(SIZE); + printf("%d", SIZE); | E = calloc(N, SIZE); + printf("%d", (N) * (SIZE)); ) However, it cannot match initializations and if-statements. I am not quite understanding your "malloc(SIZE)@S" solution. Could you point on how to use the it, or perhaps some related links? What I proposed didn't work, but the following works fine: @@ statement S; expression size; @@ ( S +printf("%d\n",size); & malloc(size) ) julia
Hi Julia,
I have tried out the following, but it seems not working.
(
D;
+ printf("%d", SIZE);
&
malloc(SIZE)
)
Best,
Yudi
Quoted 62 lines · 在 2023年4月15日 -0500 11:53,Julia Lawall <[email protected]>,写道:
Quoted 5 lines · Yudi Yang
Thank you. It now matches if-statements. However, in case of a variable initializer such as:
void* p = malloc(100);
The solution does not correctly recognize the allocation.
You should be able to use the same idea, except put D, declared as
declaration D;
julia
Quoted 46 lines
Best, Yudi
在 2023年4月15日 -0500 02:31,Julia Lawall <[email protected]>,写道:
On Sat, 15 Apr 2023, Yudi Yang wrote:
Hello Julia,
Thank you for your answer! I have modified my code:
@@
expression E, SIZE, N;
statement S;
@@
(
E = malloc(SIZE);
+printf("%d", SIZE);
|
E =calloc(N, SIZE);
+printf("%d", (N) * (SIZE));
)However, it cannot match initializations and if-statements. I am not quite understanding your "malloc(SIZE)@S" solution. Could you point on how to use the it, or perhaps some related links?
What I proposed didn't work, but the following works fine:
@@
statement S;
expression size;
@@(
S
+printf("%d\n",size);
&
malloc(size)
)julia
A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.22.394.2304172139580.2883@hadrien
Without having the “;” here, we are experiencing an error:
plus: parse error:
File "patch.cocci", line 11, column 0, charpos = 103 around = '&',
whole content = &
Quoted 94 lines · 在 2023年4月17日 -0500 14:40,Julia Lawall <[email protected]>,写道:
Quoted 5 lines · Yudi Yang
Hi Julia,
I have tried out the following, but it seems not working.(
D;I don't think you should have the semicolon. That would be matching eg int x;;
julia
Quoted 79 lines
+
printf("%d", SIZE);
&
malloc(SIZE)
)Best, Yudi
在 2023年4月15日 -0500 11:53,Julia Lawall <[email protected]>,写道:On Sat, 15 Apr 2023, Yudi Yang wrote:
Thank you. It now matches if-statements. However, in case of a variable initializer such as:
void* p = malloc(100);
The solution does not correctly recognize the
allocation.You should be able to use the same idea, except put D, declared as
declaration D;
julia
Best, Yudi
在 2023年4月15日 -0500 02:31,Julia Lawall
<[email protected]>,写道:On Sat, 15 Apr 2023, Yudi Yang wrote:
Hello Julia,
Thank you for your answer! I have modified my code:
@@
expression E, SIZE, N;
statement S;
@@
(
E = malloc(SIZE);
+printf("%d", SIZE);
|
E =calloc(N, SIZE);
+printf("%d", (N) * (SIZE));
)However, it cannot match initializations and if-statements.
I am not quite understanding your "malloc(SIZE)@S" solution.
Could you point on how to use the it, or perhaps some related links?What I proposed didn't work, but the following works fine:
@@
statement S;
expression size;
@@(
S
+printf("%d\n",size);
&
malloc(size)
)julia