diff options
author | Ilya Maximets <i.maximets@samsung.com> | 2019-02-18 18:35:02 +0300 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2019-02-22 12:48:43 -0800 |
commit | 9307fc4600ea586ecf898754acb1b37762ce7748 (patch) | |
tree | de7457044c32750a4faf137deab575a11a4a985e | |
parent | 692fc656fe530bec68373aa929367c8204bab3e7 (diff) | |
download | openvswitch-9307fc4600ea586ecf898754acb1b37762ce7748.tar.gz |
checkpatch: Escape range operators inside regex.
' -(' 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@ovn.org>
Fixes: 0d7b16daea50 ("checkpatch: Check for infix operator whitespace.")
Signed-off-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
-rwxr-xr-x | tests/checkpatch.at | 18 | ||||
-rwxr-xr-x | 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), |