From 377da7ab8e57a18a996e76c637b4e58b283abd19 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 24 Aug 2020 09:31:39 +0200 Subject: checksrc: verify do-while and spaces between the braces Updated mprintf.c to comply --- lib/checksrc.pl | 10 ++++++++++ lib/mprintf.c | 10 +++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/checksrc.pl b/lib/checksrc.pl index 498da94bb..e7eb454f1 100755 --- a/lib/checksrc.pl +++ b/lib/checksrc.pl @@ -82,6 +82,8 @@ my %warnings = ( 'SNPRINTF' => 'use of snprintf', 'ONELINECONDITION' => 'conditional block on the same line as the if()', 'TYPEDEFSTRUCT' => 'typedefed struct', + 'DOBRACE' => 'A single space between do and open brace', + 'BRACEWHILE' => 'A single space between open brace and while', ); sub readskiplist { @@ -468,6 +470,14 @@ sub scanfile { } } + # check spaces in 'do {' + if($nostr =~ /^( *)do( *)\{/ && length($2) != 1) { + checkwarn("DOBRACE", $line, length($1) + 2, $file, $l, "one space after do before brace"); + } + # check spaces in 'do {' + elsif($nostr =~ /^( *)\}( *)while/ && length($2) != 1) { + checkwarn("BRACEWHILE", $line, length($1) + 2, $file, $l, "one space between brace and while"); + } if($nostr =~ /^((.*\s)(if) *\()(.*)\)(.*)/) { my $pos = length($1); my $postparen = $5; diff --git a/lib/mprintf.c b/lib/mprintf.c index 80735be51..6b62fdfbc 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -99,12 +99,12 @@ static const char lower_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; /* Upper-case digits. */ static const char upper_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -#define OUTCHAR(x) \ - do{ \ +#define OUTCHAR(x) \ + do { \ if(stream((unsigned char)(x), (FILE *)data) != -1) \ - done++; \ - else \ - return done; /* return immediately on failure */ \ + done++; \ + else \ + return done; /* return immediately on failure */ \ } while(0) /* Data type to read from the arglist */ -- cgit v1.2.1