Coccinelle Challenge 1
Hi Julia,
I worked on the first challenge and I wanted to run my findings and questions by you. Please confirm whether these observations are correct.
I looked at the difference between local idexpression, expression, and identifier for ret.cocci.
Local idexpression basically means what local identifier would mean-- just local vars-- except that's invalid.
Using expression in place of local identifier included results like this:
- a->b = c;
- return a->b;
+ return c;
I don't know whether or not that's always the right thing to do. I think that if the changes are only local, it'd be fine to compress the lines. But if a->b happens to have a global effect than it'd be wrong. I'm not sure about this, but if the function receives *a as a parameter, then would a->b = c be a persistent change?
Using identifier included results where 'ret' was not necessarily local, so compressing the lines would be bad because the global assignment would be deleted.
I noticed some potentially bad results with ret.cocci:
1. When the type of 'ret' happens to be important, lines shouldn't be compressed. For example, a function receives a variable of type u64 but then returns it as u32. Deleting the assignment line means that the value will be returned as the wrong type.
2. spatch deletes a comment between the assignment and the return statement. E.g.:
- start = iwe(info); - /* how to translate rssi to ?% */ - return start; + return iwe(info);
}
3. readability issues--
- the return value is very long with many |'s or ||'s
- the name of the variable might be meaningful to the reader
- there are if blocks with return statements:
same variable name but different values might provide meaning/order to the program.
In these cases the variable reassignment or creation isn't actually necessary, but does it increase readability?
Questions:
I'm pretty confused about how these lines work:
-ret =
+return
e;
-return ret;
The first line deletes the name of the variable and the equals sign, but what happens to the expression on the right?
I'm confused as to why it doesn't say -ret = e to signify that the expression on the right is what we want 'e' to be. Then return gets added, and it's replacing 'ret ='. But why is 'e' even necessary if it wasn't deleted? And why is it on a new line with spaces in front? The last line '-return ret;' makes sense, we just want to delete the word return followed by the variable name.
I've read some basics of coccinelle, went through the slides, and read some articles people wrote about it but I'm still pretty confused. :/
Thanks for your time,
Elizabeth