Skip to content

Commit aeb300c

Browse files
evdenisJuliaLawall
authored andcommitted
coccinelle: misc: minmax: suppress patch generation for err returns
There is a standard idiom for "if 'ret' holds an error, return it": return ret < 0 ? ret : 0; Developers prefer to keep the things as they are because stylistic change to "return min(ret, 0);" breaks readability. Let's suppress automatic generation for this type of patches. Signed-off-by: Denis Efremov <efremov@linux.com>
1 parent 32c4656 commit aeb300c

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

scripts/coccinelle/misc/minmax.cocci

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,32 @@ func(...)
116116
...>
117117
}
118118

119+
// Don't generate patches for errcode returns.
120+
@errcode depends on patch@
121+
position p;
122+
identifier func;
123+
expression x;
124+
binary operator cmp = {<, <=};
125+
@@
126+
127+
func(...)
128+
{
129+
<...
130+
return ((x) cmp@p 0 ? (x) : 0);
131+
...>
132+
}
133+
119134
@pmin depends on patch@
120135
identifier func;
121136
expression x, y;
122137
binary operator cmp = {<=, <};
138+
position p != errcode.p;
123139
@@
124140

125141
func(...)
126142
{
127143
<...
128-
- ((x) cmp (y) ? (x) : (y))
144+
- ((x) cmp@p (y) ? (x) : (y))
129145
+ min(x, y)
130146
...>
131147
}

0 commit comments

Comments
 (0)