[ovs-dev] [PATCH] checkpatch: Escape range operators inside regex.
Ilya Maximets
i.maximets at samsung.com
Mon Feb 18 15:35:02 UTC 2019
' -(' matches a single character in the range between ' ' (index 32)
and '(' (index 40). This leads to the false positive:
WARNING: Line lacks whitespace around operator
#445 FILE: ovsdb/monitor.c:573:
if (--mcs->n_refs == 0) {
Need to escape '-' to have a right behaviour.
This patch additionally escapes all other '-' chars in the similar
regexes and makes them be one per line to ease the review in case of
future changes.
Basic unit tests added.
CC: Joe Stringer <joe at ovn.org>
Fixes: 0d7b16daea50 ("checkpatch: Check for infix operator whitespace.")
Signed-off-by: Ilya Maximets <i.maximets at samsung.com>
---
tests/checkpatch.at | 18 ++++++++++++++++++
utilities/checkpatch.py | 11 ++++++++---
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/tests/checkpatch.at b/tests/checkpatch.at
index 17976dfbb..9a72bc279 100755
--- a/tests/checkpatch.at
+++ b/tests/checkpatch.at
@@ -310,3 +310,21 @@ try_checkpatch \
"
AT_CLEANUP
+
+AT_SETUP([checkpatch - whitespace around operator])
+try_checkpatch \
+ "COMMON_PATCH_HEADER
+ + if (--mcs->n_refs == 0) {
+ "
+
+try_checkpatch \
+ "COMMON_PATCH_HEADER
+ + if (--mcs->n_refs==0) {
+ " \
+ "WARNING: Line lacks whitespace around operator
+ WARNING: Line lacks whitespace around operator
+ #8 FILE: A.c:1:
+ if (--mcs->n_refs==0) {
+"
+
+AT_CLEANUP
diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py
index 8eab31f60..4164ea8ec 100755
--- a/utilities/checkpatch.py
+++ b/utilities/checkpatch.py
@@ -612,9 +612,14 @@ infix_operators = \
[re.escape(op) for op in ['%', '<<', '>>', '<=', '>=', '==', '!=',
'^', '|', '&&', '||', '?:', '=', '+=', '-=', '*=', '/=', '%=',
'&=', '^=', '|=', '<<=', '>>=']] \
- + ['[^<" ]<[^=" ]', '[^->" ]>[^=" ]', r'[^ !()/"]\*[^/]', '[^ !&()"]&',
- r'[^" +(]\+[^"+;]', '[^" -(]-[^"->;]', r'[^" <>=!^|+\-*/%&]=[^"=]',
- '[^* ]/[^* ]']
+ + [r'[^<" ]<[^=" ]',
+ r'[^\->" ]>[^=" ]',
+ r'[^ !()/"]\*[^/]',
+ r'[^ !&()"]&',
+ r'[^" +(]\+[^"+;]',
+ r'[^" \-(]\-[^"\->;]',
+ r'[^" <>=!^|+\-*/%&]=[^"=]',
+ r'[^* ]/[^* ]']
checks += [
{'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None,
'prereq': lambda x: not is_comment_line(x),
--
2.17.1
More information about the dev
mailing list