Space-delimted string literals
I think this is a known issue, but thought I would share in case it is useful. This function:
void print_bug(char *s)
{
printf(__FILE__ ": BUG: %s\n", s);
} is not matched by this SmPL:
@ p @ expression list EL; constant C =~ "BUG"; @@ -printf(C, EL); +BUG(C, EL);
but without __FILE__ it matches:
void print_bug(char *s)
{
printf(": BUG: %s\n", s);
} I've tried to do something like this, but it is invalid SmPL:
@ p @ expression list EL; constant FOO, C =~ "BUG"; @@ -printf(FOO C, EL); +BUG(C, EL);
and produces this error:
minus: parse error: File "cocci/constant-issue", line 5, column 12, charpos = 68 around = 'C', whole content = -printf(FOO C, EL);
This isn't a critical issue in my case, only a few replacements, but string literal handling in SmPL might benefit other users.
Consider a grammar like this:
literal := literal | literal literal
Maybe the definition is a but too recursive, but you can see what I'm trying to express. Maybe keep it as a "constant" or perhaps introduce a new SmPL metavar type called "literal" or "string".
Considerations if "a" "b" "c" were being matched:
1. Specify A B C metavars and get the string in each as you would expect.
2. Specify just A and get all of them in A
3. Specify A B and A gets the first and B gets the tail as "b" "c".
Just ideas, I'm open to whatever you think is best for the project.
--
Eric Wheeler
Re: [cocci] Checking the handling of “space-delimited” string literals by SmPL
Quoted 8 lines
I've tried to do something like this, but it is invalid SmPL:
@ p @ expression list EL; constant FOO, C =~ "BUG"; @@ -printf(FOO C, EL); +BUG(C, EL);
Thanks for your interest in software adjustments also for this area.
Quoted 1 line
Just ideas, I'm open to whatever you think is best for the project.
How do you think about to influence the evolution any further also according to information from discussions around a topic like “Adding metavariable types for the handling of string literals?”?
https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2203271450370.3119@hadrien/
https://sympa.inria.fr/sympa/arc/cocci/2022-03/msg00140.html
Regards,
Markus
Re: [cocci] Checking the handling of “space-delimited” string literals by SmPL
Quoted 14 lines · Markus Elfring
Quoted 8 lines
I've tried to do something like this, but it is invalid SmPL:
@ p @ expression list EL; constant FOO, C =~ "BUG"; @@ -printf(FOO C, EL); +BUG(C, EL);Thanks for your interest in software adjustments also for this area.
Quoted 8 lines
Quoted 1 line
Just ideas, I'm open to whatever you think is best for the project.
How do you think about to influence the evolution any further also according to information from discussions around a topic like “Adding metavariable types for the handling of string literals?”?
https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2203271450370.3119@hadrien/
https://sympa.inria.fr/sympa/arc/cocci/2022-03/msg00140.html
+1 for matching (and inserting/appending to) a series of quoted literals. I could have used that a few times recently and I don't know how to use cocci+python (yet!).
--
Eric Wheeler
Quoted 5 lines
Regards,
Markus
Re: [cocci] Checking the handling of “space-delimited” string literals by SmPL
Quoted 24 lines · Eric Wheeler
Quoted 14 lines · Markus Elfring
Quoted 8 lines
I've tried to do something like this, but it is invalid SmPL:
@ p @ expression list EL; constant FOO, C =~ "BUG"; @@ -printf(FOO C, EL); +BUG(C, EL);Thanks for your interest in software adjustments also for this area.
Quoted 8 lines
Quoted 1 line
Just ideas, I'm open to whatever you think is best for the project.
How do you think about to influence the evolution any further also according to information from discussions around a topic like “Adding metavariable types for the handling of string literals?”?
https://lore.kernel.org/cocci/alpine.DEB.2.22.394.2203271450370.3119@hadrien/
https://sympa.inria.fr/sympa/arc/cocci/2022-03/msg00140.html
Quoted 3 lines
+1 for matching (and inserting/appending to) a series of quoted literals. I could have used that a few times recently and I don't know how to use cocci+python (yet!).
While such strings are surely useful, learning how to use python will be even more useful to you in the short term. Just look at the demos that contain script:python.
julia