summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2022-07-15 08:35:16 +0200
committerDr. David von Oheimb <dev@ddvo.net>2023-03-14 20:20:25 +0100
commit8299d7879d3dea724839f2cc50e980ae2375f094 (patch)
tree8767d58d8059894d00ec9ab7f663a0233abdc1e5 /util
parentb5e7dd3be3c624dde92647620cec00f6b2b35a5e (diff)
check-format.pl: report #if and #elif with constant condition; improve checks on '/*'
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> (Merged from https://github.com/openssl/openssl/pull/18812) (cherry picked from commit bdb41f92420981928578167cc6db3bcbac206cea)
Diffstat (limited to 'util')
-rw-r--r--util/check-format-test-negatives.c3
-rw-r--r--util/check-format-test-positives.c18
-rwxr-xr-xutil/check-format.pl10
3 files changed, 18 insertions, 13 deletions
diff --git a/util/check-format-test-negatives.c b/util/check-format-test-negatives.c
index 280a7a0d99..c271bd77bd 100644
--- a/util/check-format-test-negatives.c
+++ b/util/check-format-test-negatives.c
@@ -30,6 +30,9 @@
/*-
* allow extra SPC in format-tagged multi-line comment
*/
+/** allow extra '*' in comment opening */
+/*! allow extra '!' in comment opening */
+
int f(void) /*
* trailing multi-line comment
*/
diff --git a/util/check-format-test-positives.c b/util/check-format-test-positives.c
index 135ca0e832..bf750930ac 100644
--- a/util/check-format-test-positives.c
+++ b/util/check-format-test-positives.c
@@ -40,19 +40,21 @@
*@ comment starting delimiter: /* inside multi-line comment
*@ multi-line comment indent off by -1
*X*@ no spc after leading '*' in multi-line comment, reported unless sloppy-spc
- *@0 more than two spaces after . in comment, reported unless sloppy-spc
- *@0 more than two spaces after ? in comment, reported unless sloppy-spc
- *@0 more than two spaces after ! in comment, reported unless sloppy-spc
+ *@0 more than two spaces after . in comment, no more reported
+ *@0 more than two spaces after ? in comment, no more reported
+ *@0 more than two spaces after ! in comment, no more reported
*/ /*@ multi-line comment end indent off by -1 (relative to comment start) */
*/ /*@ unexpected comment ending delimiter outside comment */
+/*- '-' for formatted comment not allowed in intra-line comment */
/*@ comment line is 4 columns tooooooooooooooooo wide, reported unless sloppy-len */
/*@ comment line is 5 columns toooooooooooooooooooooooooooooooooooooooooooooo wide */
+#if ~0 /*@ '#if' with constant condition */
+ #endif /*@ indent of preproc. directive off by 1 (must be 0) */
#define X (1 + 1) /*@0 extra space in body, reported unless sloppy-spc */
-#define X 1 /*@ extra space before body, reported unless sloppy-spc */
- #define Y 2 /*@2 indent of preproc. directive off by 1 (must be 0) */ \
-#define Z /*@ preprocessor directive within multi-line directive */
+#define Y 1 /*@ extra space before body, reported unless sloppy-spc */ \
+#define Z /*@2 preprocessor directive within multi-line directive */
typedef struct { /*@0 extra space in code, reported unless sloppy-spc */
- enum { /*@1 extra space in comment, no more reported */
+ enum { /*@1 extra space in intra-line comment, no more reported */
w = 0 /*@ hanging expr indent off by 1, or 3 for lines after '{' */
&& 1, /*@ hanging expr indent off by 3, or -1 for leading '&&' */
x = 1, /*@ hanging expr indent off by -1 */
@@ -344,7 +346,7 @@ void f_looong_body()
; /*@ 2 essentially blank lines before, if !sloppy-spc */
} /*@ function body length > 200 lines */
-#if 0 /*@0 unclosed #if */
+#if X /*@0 unclosed #if */
struct t { /*@0 unclosed brace at decl/block level */
enum { /*@0 unclosed brace at enum/expression level */
v = (1 /*@0 unclosed parenthesis */
diff --git a/util/check-format.pl b/util/check-format.pl
index 285c1f1e46..a997460396 100755
--- a/util/check-format.pl
+++ b/util/check-format.pl
@@ -606,8 +606,8 @@ while (<>) { # loop over all lines of all input files
# detect end of comment, must be within multi-line comment, check if it is preceded by non-whitespace text
if ((my ($head, $tail) = m|^(.*?)\*/(.*)$|) && $1 ne '/') { # ending comment: '*/'
- report("neither space nor '*' before '*/'") if $head =~ m/[^*\s]$/;
- report("missing space after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/'
+ report("missing space or '*' before '*/'") if $head =~ m/[^*\s]$/;
+ report("missing space (or ',', ';', ')', '}', ']') after '*/'") if $tail =~ m/^[^\s,;)}\]]/; # no space or ,;)}] after '*/'
if (!($head =~ m|/\*|)) { # not begin of comment '/*', which is is handled below
if ($in_comment == 0) {
report("unexpected '*/' outside comment");
@@ -632,7 +632,7 @@ while (<>) { # loop over all lines of all input files
if (my ($head, $opt_minus, $tail) = m|^(.*?)/\*(-?)(.*)$|) { # begin of comment: '/*'
report("missing space before '/*'")
if $head =~ m/[^\s(\*]$/; # not space, '(', or or '*' (needed to allow '*/') before comment delimiter
- report("missing space, '*' or '!' after '/*' or '/*-'") if $tail =~ m/^[^*\s!$self_test_exception]/;
+ report("missing space, '*', or '!' after '/*$opt_minus'") if $tail =~ m/^[^\s*!$self_test_exception]/;
my $cmt_text = $opt_minus.$tail; # preliminary
if ($in_comment > 0) {
report("unexpected '/*' inside multi-line comment");
@@ -705,6 +705,8 @@ while (<>) { # loop over all lines of all input files
}
$in_preproc++;
report("indent = $count != 0 for '#'") if $count != 0;
+ report("'#$preproc_directive' with constant condition")
+ if $preproc_directive =~ m/^(if|elif)$/ && m/^[\W0-9]+$/ && !$trailing_backslash;
$preproc_if_nesting-- if $preproc_directive =~ m/^(else|elif|endif)$/;
if ($preproc_if_nesting < 0) {
$preproc_if_nesting = 0;
@@ -978,8 +980,6 @@ while (<>) { # loop over all lines of all input files
if (m/(['"]|([\+\-\*\/\/%\&\|\^<>]\s*)?\W[0-9]+L?|\WNULL)\s*([\!<>=]=|[<=>])([<>]?)/ &&
$2 eq "" && (($3 ne "<" && $3 ne "='" && $3 ne ">") || $4 eq ""));
- # TODO report #if 0 and #if 1
-
# TODO report needless use of parentheses, while
# macro parameters should always be in parens (except when passed on), e.g., '#define ID(x) (x)'