mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
checksrc: complain on == NULL or != 0 checks in conditions
... to make them all consistenly use if(!var) and if(var) Also added a few missing warnings to the documentation. Closes #6912
This commit is contained in:
parent
063d3f3b96
commit
52fab72397
@ -33,8 +33,9 @@ warnings are:
|
|||||||
- `ASSIGNWITHINCONDITION`: Assignment within a conditional expression. The
|
- `ASSIGNWITHINCONDITION`: Assignment within a conditional expression. The
|
||||||
code style mandates the assignment to be done outside of it.
|
code style mandates the assignment to be done outside of it.
|
||||||
|
|
||||||
- `ASTERISKNOSPACE`: A pointer was declared like `char* name` instead of the more
|
- `ASTERISKNOSPACE`: A pointer was declared like `char* name` instead of the
|
||||||
appropriate `char *name` style. The asterisk should sit next to the name.
|
more appropriate `char *name` style. The asterisk should sit next to the
|
||||||
|
name.
|
||||||
|
|
||||||
- `ASTERISKSPACE`: A pointer was declared like `char * name` instead of the
|
- `ASTERISKSPACE`: A pointer was declared like `char * name` instead of the
|
||||||
more appropriate `char *name` style. The asterisk should sit right next to
|
more appropriate `char *name` style. The asterisk should sit right next to
|
||||||
@ -51,12 +52,24 @@ warnings are:
|
|||||||
|
|
||||||
- `BRACEPOS`: wrong position for an open brace (`{`).
|
- `BRACEPOS`: wrong position for an open brace (`{`).
|
||||||
|
|
||||||
|
- `BRACEWHILE`: more than once space between end brace and while keyword
|
||||||
|
|
||||||
- `COMMANOSPACE`: a comma without following space
|
- `COMMANOSPACE`: a comma without following space
|
||||||
|
|
||||||
- `COPYRIGHT`: the file is missing a copyright statement!
|
- `COPYRIGHT`: the file is missing a copyright statement!
|
||||||
|
|
||||||
- `CPPCOMMENTS`: `//` comment detected, that's not C89 compliant
|
- `CPPCOMMENTS`: `//` comment detected, that's not C89 compliant
|
||||||
|
|
||||||
|
- `DOBRACE`: only use one space after do before open brace
|
||||||
|
|
||||||
|
- `EMPTYLINEBRACE`: found empty line before open brace
|
||||||
|
|
||||||
|
- `EQUALSNOSPACE`: no space after `=` sign
|
||||||
|
|
||||||
|
- `EQUALSNULL`: comparison with `== NULL` used in if/while. We use `!var`.
|
||||||
|
|
||||||
|
- `EXCLAMATIONSPACE`: space found after exclamations mark
|
||||||
|
|
||||||
- `FOPENMODE`: `fopen()` needs a macro for the mode string, use it
|
- `FOPENMODE`: `fopen()` needs a macro for the mode string, use it
|
||||||
|
|
||||||
- `INDENTATION`: detected a wrong start column for code. Note that this
|
- `INDENTATION`: detected a wrong start column for code. Note that this
|
||||||
@ -70,6 +83,8 @@ warnings are:
|
|||||||
- `NOSPACEEQUALS`: An equals sign was found without preceding space. We prefer
|
- `NOSPACEEQUALS`: An equals sign was found without preceding space. We prefer
|
||||||
`a = 2` and *not* `a=2`.
|
`a = 2` and *not* `a=2`.
|
||||||
|
|
||||||
|
- `NOTEQUALSZERO`: check found using `!= 0`. We use plain `if(var)`.
|
||||||
|
|
||||||
- `ONELINECONDITION`: do not put the conditional block on the same line as `if()`
|
- `ONELINECONDITION`: do not put the conditional block on the same line as `if()`
|
||||||
|
|
||||||
- `OPENCOMMENT`: File ended with a comment (`/*`) still "open".
|
- `OPENCOMMENT`: File ended with a comment (`/*`) still "open".
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# | (__| |_| | _ <| |___
|
# | (__| |_| | _ <| |___
|
||||||
# \___|\___/|_| \_\_____|
|
# \___|\___/|_| \_\_____|
|
||||||
#
|
#
|
||||||
# Copyright (C) 2011 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
|
# Copyright (C) 2011 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||||
#
|
#
|
||||||
# This software is licensed as described in the file COPYING, which
|
# This software is licensed as described in the file COPYING, which
|
||||||
# you should have received as part of this distribution. The terms
|
# you should have received as part of this distribution. The terms
|
||||||
@ -86,6 +86,8 @@ my %warnings = (
|
|||||||
'BRACEWHILE' => 'A single space between open brace and while',
|
'BRACEWHILE' => 'A single space between open brace and while',
|
||||||
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
|
'EXCLAMATIONSPACE' => 'Whitespace after exclamation mark in expression',
|
||||||
'EMPTYLINEBRACE' => 'Empty line before the open brace',
|
'EMPTYLINEBRACE' => 'Empty line before the open brace',
|
||||||
|
'EQUALSNULL' => 'if/while comparison with == NULL',
|
||||||
|
'NOTEQUALSZERO' => 'if/while comparison with != 0'
|
||||||
);
|
);
|
||||||
|
|
||||||
sub readskiplist {
|
sub readskiplist {
|
||||||
@ -471,6 +473,21 @@ sub scanfile {
|
|||||||
"$2 with space");
|
"$2 with space");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
# check for '== NULL' in if/while conditions but not if the thing on
|
||||||
|
# the left of it is a function call
|
||||||
|
if($nostr =~ /^(.*)(if|while)(\(.*[^)]) == NULL/) {
|
||||||
|
checkwarn("EQUALSNULL", $line,
|
||||||
|
length($1) + length($2) + length($3),
|
||||||
|
$file, $l, "we prefer !variable instead of \"== NULL\" comparisons");
|
||||||
|
}
|
||||||
|
|
||||||
|
# check for '!= 0' in if/while conditions but not if the thing on
|
||||||
|
# the left of it is a function call
|
||||||
|
if($nostr =~ /^(.*)(if|while)(\(.*[^)]) != 0[^x]/) {
|
||||||
|
checkwarn("NOTEQUALSZERO", $line,
|
||||||
|
length($1) + length($2) + length($3),
|
||||||
|
$file, $l, "we prefer if(rc) instead of \"rc != 0\" comparisons");
|
||||||
|
}
|
||||||
|
|
||||||
# check spaces in 'do {'
|
# check spaces in 'do {'
|
||||||
if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) {
|
if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) {
|
||||||
|
Loading…
Reference in New Issue
Block a user