Skip to contentSkip to conversation

Checking exception handling implementations with SmPL

Cocci SF Markus Elfring 2 participants 7 messages May 14, 2017 – May 23, 2017

lore
Share & tools
lore
#0 lore raw

Hello,

I would like to check the implementation of exception handling in various source files. The following script for the semantic patch language tries to express a few possibilities for such a source code search pattern.

@show_special_reactions@
expression error_code, var;
identifier action =~ "^(?:malloc|strdup)$",

           no_return =~ "[Aa]bort",
           label;

statement es;
@@
var = action(...);
if (failed(var))
{
(
* return error_code;
|
* goto label;
|
* no_return();
)
}
else
es

I find this approach too simple and therefore incomplete. Three well-known reactions are shown. But there can be more source code before these statements like further function calls and variable assignments.
We do eventually not know the extra code there and it can also be generally optional.

How can the Coccinelle software help any more in such an use case?

Regards,
Markus

#1 lore raw

[Cocci] Checking source code (including optional parts) with SmPL

I would like to clarify the possibilities for corresponding software extensions a bit more.
The Coccinelle software provides also the search operator ?question mark? which denotes code on a specific line as optional.
https://github.com/coccinelle/coccinelle/blob/9b5e00862900b0daadf1819a6894d31544a3ba34/docs/manual/cocci_syntax.tex#L1067

The scope of the special code there is only the marked line so that I see some software development challenges to pack desired search filters into one line.

* How often do you check the handling for optional parts?

- Do you find it relevant to check for the assignment of an error code to an other variable?

- Are special constraints needed for additional function calls?

* How are the chances to improve readability and maintainability for SmPL code?

Regards,
Markus

#2 lore raw

[Cocci] Safe determination of function properties for SmPL scripts

In reply to SF Markus Elfring
Quoted 1 line

How can the Coccinelle software help any more in such an use case?

This small SmPL script example demonstrates two special selections of functions by their name. They belong to separate categories then.

* The primary actions should usually provide a return value somehow.

* A call of a function which will not return from its final task is one possibility for an error reaction.

Have you got any preferences for the determination and integration of name lists for functions with the desired properties into the semantic patch language in a safe way?

Would you dare to query a database table (or view) for such a purpose?

Regards,
Markus

#3 lore raw

[Cocci] Checking failure predicates with SmPL

In reply to SF Markus Elfring
Quoted 2 lines

var = action(...);
if (failed(var))

This SmPL specification contains a few further software development challenges.

1. It could be taken into account that a function call and a corresponding check for the return value are not directly next to each other.
A SmPL ellipsis could be added there. But I guess that special restrictions will be needed then for a safe ?when specification?.

2. The check which should appropriately be performed for a return code depends on the called function.
* Each failure predicate could be written as a separate SmPL rule. This approach would result into code duplication to some degree.

* I would prefer to keep the selection and data processing for the desired predicate at a single place. But I am unsure so far how good such a variant is supported by the current Coccinelle software.

Regards,
Markus

#4 lore raw

[Cocci] Easier search for assignment targets with SmPL

In reply to SF Markus Elfring
Quoted 1 line

var = action(...);

This specification looks also simple for the semantic patch language at first glance.
I tried to express that a specific value is assigned to something. But this ?something? could be a different item depending on the position in the source code.

1. Variable
2. Expression
3. Element for a designated initialiser

I would appreciate if I do not need to repeat specifications for these cases in SmPL code. How do you think about the possibility to support the desired source code search by an additional metavariable type there?
Can it become safer and more convenient to handle assignments here?

Regards,
Markus

#5 lore raw

[Cocci] Easier search for assignment targets with SmPL

Quoted 8 lines · SF Markus Elfring
Quoted 1 line

var = action(...);

This specification looks also simple for the semantic patch language at first glance.
I tried to express that a specific value is assigned to something. But this ?something? could be a different item depending on the position in the source code.

Quoted 8 lines

1. Variable
2. Expression
3. Element for a designated initialiser

I would appreciate if I do not need to repeat specifications for these cases in SmPL code. How do you think about the possibility to support the desired source code search by an additional metavariable type there?
Can it become safer and more convenient to handle assignments here?

I have no idea what you are asking for. In any case, an expression metavariable already matches a variable. I don't know what a designated initializer is.

julia

Quoted 8 lines

Regards,
Markus
_______________________________________________
Cocci mailing list
Cocci at systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

#6 lore raw

[Cocci] Easier search for assignment targets with SmPL

Quoted 3 lines
Quoted 1 line

Can it become safer and more convenient to handle assignments here?

I have no idea what you are asking for.

I wonder about such a kind of feedback.

Quoted 1 line

In any case, an expression metavariable already matches a variable.

This information can be appropriate in some source code situations.

Do you care for any more ?special use cases??

Quoted 1 line

I don't know what a designated initializer is.

I find this aspect strange when it was already discussed several times.
http://en.cppreference.com/w/c/language/struct_initialization

How would you prefer to handle various software development challenges around specifications for variable definitions?

Regards,
Markus