]> git.ipfire.org Git - thirdparty/systemd.git/blame - coccinelle/strempty.cocci
licensing: add spdx to our .cocci files
[thirdparty/systemd.git] / coccinelle / strempty.cocci
CommitLineData
64b92d63 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
de896126 2@@
e4ff0393
FS
3/* Avoid running this transformation on the strempty function itself and
4 * on the "make_expression" macro in src/libsystemd/sd-bus/bus-convenience.c.
5 * As Coccinelle's Location object doesn't support macro "detection", use
6 * a pretty horrifying combo of specifying a file and a special "something_else"
7 * position element, which is, apparently, the default value of
8 * "current_element" before it's set (according to the source code), thus
9 * matching any "top level" position, including macros. Let's hope we never
10 * introduce a function called "something_else"...
11 */
12position p : script:python() {
13 not (p[0].current_element == "strempty" or
14 (p[0].file == "src/libsystemd/sd-bus/bus-convenience.c" and
15 p[0].current_element == "something_else"))
16};
de896126
DM
17expression s;
18@@
60d9959d
FS
19(
20- s@p ?: ""
de896126 21+ strempty(s)
60d9959d
FS
22|
23- s@p ? s : ""
de896126 24+ strempty(s)
60d9959d
FS
25)
26
ad5d4b17 27@@
60d9959d 28position p : script:python() { p[0].current_element != "strempty" };
ad5d4b17
LP
29expression s;
30@@
60d9959d 31- if (!s@p)
ad5d4b17
LP
32- s = "";
33+ s = strempty(s);
60d9959d 34
ad5d4b17 35@@
60d9959d 36position p : script:python() { p[0].current_element != "strnull" };
ad5d4b17
LP
37expression s;
38@@
60d9959d
FS
39(
40- s@p ?: "(null)"
ad5d4b17 41+ strnull(s)
60d9959d
FS
42|
43- s@p ? s : "(null)"
ad5d4b17 44+ strnull(s)
60d9959d
FS
45)
46
ad5d4b17 47@@
60d9959d 48position p : script:python() { p[0].current_element != "strnull" };
ad5d4b17
LP
49expression s;
50@@
60d9959d 51- if (!s@p)
ad5d4b17
LP
52- s = "(null)";
53+ s = strnull(s);
60d9959d 54
ad5d4b17 55@@
60d9959d 56position p : script:python() { p[0].current_element != "strna" };
ad5d4b17
LP
57expression s;
58@@
60d9959d
FS
59(
60- s@p ?: "n/a"
ad5d4b17 61+ strna(s)
60d9959d
FS
62|
63- s@p ? s : "n/a"
ad5d4b17 64+ strna(s)
60d9959d
FS
65)
66
ad5d4b17 67@@
60d9959d 68position p : script:python() { p[0].current_element != "strna" };
ad5d4b17
LP
69expression s;
70@@
60d9959d 71- if (!s@p)
ad5d4b17
LP
72- s = "n/a";
73+ s = strna(s);