Skip to contentSkip to conversation

Checking data structure modification with SmPL

Cocci SF Markus Elfring 2 participants 8 messages Aug 18, 2015 – Aug 22, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hello,

I have tried another small SmPL script out.

@show_modification_before_memory_release@
expression value;
identifier element, var;
@@
<+...
*var->element = value;
...+>
free(var);

This approach is working to some degree.
Now I would like to support more possibilities for the determination of affected members from the shown variable.

@show_modification_before_memory_release@
expression element, value;
identifier var;
@@
<+...
*var->element = value;
...+>
free(var);

elfring at Sonne:~/Projekte/Miller/lokal> spatch.opt -sp-file ~/Projekte/Coccinelle/janitor/show_modification_before_memory_release1.cocci c/containers/hss.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
101 108
Fatal error: exception Failure("minus: parse error: \n = File \"/home/elfring/Projekte/Coccinelle/janitor/show_modification_before_memory_release1.cocci\", line 6, column 6, charpos = 101\n around = 'element', whole content = *var->element = value;\n")

How can this source code analysis be improved?

Regards,
Markus

#1 lore raw
Quoted 19 lines · SF Markus Elfring

Hello,

I have tried another small SmPL script out.

@show_modification_before_memory_release@
expression value;
identifier element, var;
@@
<+...
*var->element = value;
...+>
free(var);

This approach is working to some degree.
Now I would like to support more possibilities for the determination of affected members from the shown variable.

Quoted 6 lines

@show_modification_before_memory_release@
expression element, value;
identifier var;
@@
<+...
*var->element = value;

Element is not an expression. An expression is something that has a value. A field name has no value. It just enables selecting a field. Probably what you want is <+...var->element...+>, ie something that has var->element as a subexpression. To avoid parsing ambiguities, you will need to put () around this, but it will not affect the results.

julia

Quoted 19 lines

...+>
free(var);

elfring at Sonne:~/Projekte/Miller/lokal> spatch.opt -sp-file ~/Projekte/Coccinelle/janitor/show_modification_before_memory_release1.cocci c/containers/hss.c
init_defs_builtins: /usr/local/lib/coccinelle/standard.h
101 108
Fatal error: exception Failure("minus: parse error: \n = File \"/home/elfring/Projekte/Coccinelle/janitor/show_modification_before_memory_release1.cocci\", line 6, column 6, charpos = 101\n around = 'element', whole content = *var->element = value;\n")

How can this source code analysis be improved?

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

#2 lore raw
Quoted 11 lines
Quoted 10 lines

Now I would like to support more possibilities for the determination of affected members from the shown variable.

@show_modification_before_memory_release@
expression element, value;
identifier var;
@@
<+...
*var->element = value;

Quoted 2 lines

Element is not an expression. An expression is something that has a value. A field name has no value. It just enables selecting a field.

Thanks for your clarification.

Quoted 2 lines

Probably what you want is <+...var->element...+>, ie something that has var->element as a subexpression.

* Do I need to restrict the amount of source code which can appear between data structure access and the shown value assignment that should be checked by such a SmPL construct?

* Do I need to fiddle with another SmPL disjunction to express the possibility that "var" could be more than a simple identifier?

* How should the support for longer arrow chains be specified?

Quoted 2 lines

To avoid parsing ambiguities, you will need to put () around this, but it will not affect the results.

Thanks for this hint.

Quoted 2 lines
Quoted 2 lines

...+>
free(var);

Regards,
Markus

#3 lore raw
Quoted 17 lines · SF Markus Elfring
Quoted 11 lines
Quoted 10 lines

Now I would like to support more possibilities for the determination of affected members from the shown variable.

@show_modification_before_memory_release@
expression element, value;
identifier var;
@@
<+...
*var->element = value;

Quoted 2 lines

Element is not an expression. An expression is something that has a value. A field name has no value. It just enables selecting a field.

Thanks for your clarification.

Quoted 6 lines
Quoted 2 lines

Probably what you want is <+...var->element...+>, ie something that has var->element as a subexpression.

* Do I need to restrict the amount of source code which can appear between data structure access and the shown value assignment that should be checked by such a SmPL construct?

Since I don'tknow what you want to do, I can't tell you. If there are somefixed patterns you want to find, it would be better to enumerate those fixed patterns.

Quoted 2 lines

* Do I need to fiddle with another SmPL disjunction to express the possibility that "var" could be more than a simple identifier?

Ultimately, var shouldend up at an identifier, so I don't see the need.

Quoted 1 line

* How should the support for longer arrow chains be specified?

No idea what you are asking, but I am not keen on adding yet another metavariable type for this, which anyway doesn't correspond to anything in the C grammar.

julia

Quoted 15 lines
Quoted 4 lines

To avoid parsing ambiguities, you will need to put () around this, but it will not affect the results.

Thanks for this hint.

Quoted 2 lines
Quoted 2 lines

...+>
free(var);

Regards,
Markus

#4 lore raw
Quoted 4 lines
Quoted 2 lines

* Do I need to fiddle with another SmPL disjunction to express the possibility that "var" could be more than a simple identifier?

Ultimately, var shouldend up at an identifier, so I don't see the need.

How do you think about a variant like the following?

(expression)->element

Quoted 5 lines
Quoted 1 line

* How should the support for longer arrow chains be specified?

No idea what you are asking, but I am not keen on adding yet another metavariable type for this, which anyway doesn't correspond to anything in the C grammar.

Does the following approach make my consideration a bit more clear?

var->(expression)->(expression)->element

How should a more detailed pointer access variation be handled here?

Regards,
Markus

#5 lore raw
Quoted 8 lines · SF Markus Elfring
Quoted 4 lines
Quoted 2 lines

* Do I need to fiddle with another SmPL disjunction to express the possibility that "var" could be more than a simple identifier?

Ultimately, var shouldend up at an identifier, so I don't see the need.

How do you think about a variant like the following?

(expression)->element

This is certainly possible. Depends whether you want the innermost variable or the outermost expression.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

* How should the support for longer arrow chains be specified?

No idea what you are asking, but I am not keen on adding yet another metavariable type for this, which anyway doesn't correspond to anything in the C grammar.

Does the following approach make my consideration a bit more clear?

var->(expression)->(expression)->element

This makes no sense. If you have a->b->c->d->e, then eg b->c->d is not an expression. It has no value.

julia

Quoted 6 lines

How should a more detailed pointer access variation be handled here?

Regards,
Markus

#6 lore raw
Quoted 1 line

If you have a->b->c->d->e, then eg b->c->d is not an expression.

I have got an other opinion here.

* Can each part between the pointer access operators be an expression?

* How long can such a structure member access chain become in interesting source codes?

Regards,
Markus

A message that is not in the archive (sent off-list or not yet received): alpine.DEB.2.10.1508221303590.2446@hadrien

#8 lore raw
Quoted 4 lines
Quoted 1 line

* Can each part between the pointer access operators be an expression?

No. In a->b->c->d->e, b->c->d has no value. It even has no meaning independent of the type of a.

Which wording would be more appropriate from the point of view in the syntax of the C programming language?

Quoted 6 lines
Quoted 2 lines

* How long can such a structure member access chain become in interesting source codes?

I guess as long as the greatest nesting depth of structures in the program. If the program contains structures of recursive type, it ca have any length.

Can I prepare SmPL scripts to handle variations there?

How are the chances to avoid the consideration and source code analysis around only a limited number of structure member accesses?

Regards,
Markus