Question on expression meaning
Hello,
I'm trying to achieve the following:
void DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq) {
...
/* now process the Ext headers and/or the L4 Layer */
switch(IPV6_GET_NH(p)) {
case IPPROTO_TCP:
IPV6_SET_L4PROTO (p, IPPROTO_TCP);- return DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq);
+ DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq);
+ return;
DecodeTCP being a function returning void too. In fact Solaris compiler does not accept void function to return a void function.
My first try was:
@@
identifier f;
identifier g;
@@
void f(...)
{
...
- return g(...);
+ g(...);
+ return;
...
}
But this does not work because the ... can not be put on - + lines.
I've tried the not specific semantic patch:
@@
identifier f;
expression E;
@@
void f(...)
{
...
- return E;
+ E;
+ return;
...
}
But it does not work for function (it works for "return 42;"). Any idea ?
BR,
--
Eric
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20130802/f03fb3e2/attachment.asc>
Quoted 52 lines · Eric Leblond
Hello,
I'm trying to achieve the following:
void
DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq){
...
/* now process the Ext headers and/or the L4 Layer */switch(IPV6_GET_NH(p)) { case IPPROTO_TCP: IPV6_SET_L4PROTO (p, IPPROTO_TCP);(quoted diff) +2
-1- return DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq); + DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq); + return;DecodeTCP being a function returning void too. In fact Solaris compiler does not accept void function to return a void function.
My first try was:
@@
identifier f;
identifier g;
@@void f(...)
{
...
- return g(...);
+ g(...);
+ return;
...
}But this does not work because the ... can not be put on - + lines.
I've tried the not specific semantic patch:
@@
identifier f;
expression E;
@@void f(...)
{
...
- return E;
+ E;
+ return;
...
}
Quoted 1 line
But it does not work for function (it works for "return 42;"). Any idea ?
It is quite strange that it does not work for a function call. I will look into it.
But if you want to focus on function calls, what could be best is the following (not tested):
- return
g(...);
+ return;
That way you preserve the spacing and newlines in the function call. There could be some other formatting problems in the result, though.
The other solution would be to make the argument of g be a metavariable declared as:
expression list es;
Then you can remove it and add it back. But you will probably lose any newlines within es.
julia
Hi,
If you don't need f anywhere else, the following should be enough.
@@
identifier f;
@@
- return
f(...);
+ return;
Quoted 86 lines · Julia Lawall
Quoted 55 lines · Eric Leblond
Hello,
I'm trying to achieve the following:
void
DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
{
...
/* now process the Ext headers and/or the L4 Layer */switch(IPV6_GET_NH(p)) { case IPPROTO_TCP: IPV6_SET_L4PROTO (p, IPPROTO_TCP);- return DecodeTCP(tv, dtv, p, pkt +
IPV6_HEADER_LEN,IPV6_GET_PLEN(p), pq);
+ DecodeTCP(tv, dtv, p, pkt +IPV6_HEADER_LEN,IPV6_GET_PLEN(p), pq);
+ return;DecodeTCP being a function returning void too. In fact Solaris compiler does not accept void function to return a void function.
My first try was:
@@
identifier f;
identifier g;
@@void f(...)
{
...
- return g(...);
+ g(...);
+ return;
...
}But this does not work because the ... can not be put on - + lines.
I've tried the not specific semantic patch:
@@
identifier f;
expression E;
@@void f(...)
{
...
- return E;
+ E;
+ return;
...
}Quoted 1 line
But it does not work for function (it works for "return 42;"). Any idea ?
It is quite strange that it does not work for a function call. I will look into it.
But if you want to focus on function calls, what could be best is the following (not tested):
- return
g(...);+ return;
That way you preserve the spacing and newlines in the function call. There could be some other formatting problems in the result, though.
The other solution would be to make the argument of g be a metavariable declared as:
expression list es;
Then you can remove it and add it back. But you will probably lose any newlines within es.
julia
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci
Signature · 3 lines
Nicolas Palix Tel: +33 4 76 51 46 27 http://membres-liglab.imag.fr/palix/
Quoted 11 lines · Nicolas Palix
Hi,
If you don't need f anywhere else, the following should be enough.
@@
identifier f;
@@- return
f(...);
+ return;
He needs to be sure that the return type is void.
julia
Quoted 95 lines · Julia Lawall
Quoted 86 lines · Eric Leblond
Quoted 56 lines
Hello,
I'm trying to achieve the following:
void
DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq)
{
...
/* now process the Ext headers and/or the L4 Layer */switch(IPV6_GET_NH(p)) { case IPPROTO_TCP: IPV6_SET_L4PROTO (p, IPPROTO_TCP);- return DecodeTCP(tv, dtv, p, pkt +
IPV6_HEADER_LEN,IPV6_GET_PLEN(p), pq);
+ DecodeTCP(tv, dtv, p, pkt +IPV6_HEADER_LEN,IPV6_GET_PLEN(p), pq);
+ return;DecodeTCP being a function returning void too. In fact Solaris compiler does not accept void function to return a void function.
My first try was:
@@
identifier f;
identifier g;
@@void f(...)
{
...
- return g(...);
+ g(...);
+ return;
...
}But this does not work because the ... can not be put on - + lines.
I've tried the not specific semantic patch:
@@
identifier f;
expression E;
@@void f(...)
{
...
- return E;
+ E;
+ return;
...
}Quoted 1 line
But it does not work for function (it works for "return 42;"). Any idea ?
It is quite strange that it does not work for a function call. I will look into it.
But if you want to focus on function calls, what could be best is the following (not tested):
- return
g(...);+ return;
That way you preserve the spacing and newlines in the function call. There could be some other formatting problems in the result, though.
The other solution would be to make the argument of g be a metavariable declared as:
expression list es;
Then you can remove it and add it back. But you will probably lose any newlines within es.
julia
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocciSignature · 3 lines
Nicolas Palix Tel: +33 4 76 51 46 27 http://membres-liglab.imag.fr/palix/
Hi,
Le vendredi 02 ao?t 2013 ? 11:37 +0200, Julia Lawall a ?crit :
Quoted 54 lines · Eric Leblond
Quoted 53 lines
Hello,
I'm trying to achieve the following:
void
DecodeIPV6(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, uint8_t *pkt, uint16_t len, PacketQueue *pq){
...
/* now process the Ext headers and/or the L4 Layer */switch(IPV6_GET_NH(p)) { case IPPROTO_TCP: IPV6_SET_L4PROTO (p, IPPROTO_TCP);(quoted diff) +2
-1- return DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq); + DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq); + return;DecodeTCP being a function returning void too. In fact Solaris compiler does not accept void function to return a void function.
My first try was:
@@
identifier f;
identifier g;
@@void f(...)
{
...
- return g(...);
+ g(...);
+ return;
...
}But this does not work because the ... can not be put on - + lines.
I've tried the not specific semantic patch:
@@
identifier f;
expression E;
@@void f(...)
{
...
- return E;
+ E;
+ return;
...
}
Quoted 4 lines
Quoted 1 line
But it does not work for function (it works for "return 42;"). Any idea ?
It is quite strange that it does not work for a function call. I will look into it.
Sorry for bad information. Reading your previous mail, I understood that there was a difference as I've put the 'return 42;' at start of the function. So it was always reached.
And thanks for the help, it works correctly now!
--
Eric
Quoted 14 lines
But if you want to focus on function calls, what could be best is the following (not tested):
- return
g(...);+ return;
That way you preserve the spacing and newlines in the function call. There could be some other formatting problems in the result, though.
The other solution would be to make the argument of g be a metavariable declared as:
Quoted 6 lines
expression list es;
Then you can remove it and add it back. But you will probably lose any newlines within es.
julia
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part
URL: <https://systeme.lip6.fr/pipermail/cocci/attachments/20130802/1ce2d929/attachment.asc>
Quoted 16 lines
I've tried the not specific semantic patch:
@@
identifier f;
expression E;
@@void f(...)
{
...
- return E;
+ E;
+ return;
...
}
Quoted 1 line
But it does not work for function (it works for "return 42;"). Any idea ?
I'm not sure what was your exact original program. This rule is making a transformation, and so it requires the pattern following the ... to be reachable on all control-flow paths. If I try the rule on:
void main () {
switch(IPV6_GET_NH(p)) {
case IPPROTO_TCP:
IPV6_SET_L4PROTO (p, IPPROTO_TCP);
return DecodeTCP(tv, dtv, p, pkt + IPV6_HEADER_LEN, IPV6_GET_PLEN(p), pq); }
}
it doesn't work, because there is not a return on all control-flow paths. On the other hand, if I put a return 7; at the end of the function, then it changes both returns.
Probably what you really want is the following:
void f(...)
{
<...
- return E;
+ E;
+ return;
...>
}
This will just change the return wherever it occurs.
julia