mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 20:23:36 +08:00
60d9959dd8
For example, following transformation: - isempty(s) ? NULL : s + empty_to_null(s) would get applied to the empty_to_null function itself as well, causing an infinite recursion, like: --- src/basic/string-util.h +++ /tmp/cocci-output-307-9f76e6-string-util.h @@ -50,11 +50,11 @@ static inline bool isempty(const char *p } static inline const char *empty_to_null(const char *p) { - return isempty(p) ? NULL : p; + return empty_to_null(p); } Let's avoid that by checking the current match position
61 lines
948 B
Plaintext
61 lines
948 B
Plaintext
@@
|
|
/* Avoid running this transformation on the strempty function itself */
|
|
position p : script:python() { p[0].current_element != "strempty" };
|
|
expression s;
|
|
@@
|
|
(
|
|
- s@p ?: ""
|
|
+ strempty(s)
|
|
|
|
|
- s@p ? s : ""
|
|
+ strempty(s)
|
|
)
|
|
|
|
@@
|
|
position p : script:python() { p[0].current_element != "strempty" };
|
|
expression s;
|
|
@@
|
|
- if (!s@p)
|
|
- s = "";
|
|
+ s = strempty(s);
|
|
|
|
@@
|
|
position p : script:python() { p[0].current_element != "strnull" };
|
|
expression s;
|
|
@@
|
|
(
|
|
- s@p ?: "(null)"
|
|
+ strnull(s)
|
|
|
|
|
- s@p ? s : "(null)"
|
|
+ strnull(s)
|
|
)
|
|
|
|
@@
|
|
position p : script:python() { p[0].current_element != "strnull" };
|
|
expression s;
|
|
@@
|
|
- if (!s@p)
|
|
- s = "(null)";
|
|
+ s = strnull(s);
|
|
|
|
@@
|
|
position p : script:python() { p[0].current_element != "strna" };
|
|
expression s;
|
|
@@
|
|
(
|
|
- s@p ?: "n/a"
|
|
+ strna(s)
|
|
|
|
|
- s@p ? s : "n/a"
|
|
+ strna(s)
|
|
)
|
|
|
|
@@
|
|
position p : script:python() { p[0].current_element != "strna" };
|
|
expression s;
|
|
@@
|
|
- if (!s@p)
|
|
- s = "n/a";
|
|
+ s = strna(s);
|