All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Sven Eckelmann <sven@narfation.org>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Whitcroft <apw@canonical.com>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] checkpatch: remove false unbalanced braces warning
Date: Mon, 20 Feb 2017 18:42:58 -0800	[thread overview]
Message-ID: <1487644978.2853.8.camel@perches.com> (raw)
In-Reply-To: <20170220121644.12209-1-sven@narfation.org>

On Mon, 2017-02-20 at 13:16 +0100, Sven Eckelmann wrote:
> Lines containing "} else {" should not be detected as unbalanced braces.
> But the second check can be reduced to ".+else\s*{" and it therefore
> never checked if the beginning of a line contains any other character
> (like the relevant "}"). This check would also return true for
> "} else {" and create warnings like

Yeah, thanks.  That's what I meant to do originally.

Acked-by: Joe Perches <joe@perches.com>

cheers, Joe

>     CHECK: Unbalanced braces around else statement
>     #391: FILE: ./net/batman-adv/tvlv.c:391:
>     +   } else {
> 
> The check can be changed to check the whole line for the missing "}" to
> avoid this false positive.
> 
> Fixes: 0d1532456c26 ("checkpatch: notice unbalanced else braces in a patch")
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
>  scripts/checkpatch.pl | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index ad5ea5c545b2..baa3c7be04ad 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5107,8 +5107,8 @@ sub process {
>  		}
>  
>  # check for single line unbalanced braces
> -		if ($sline =~ /.\s*\}\s*else\s*$/ ||
> -		    $sline =~ /.\s*else\s*\{\s*$/) {
> +		if ($sline =~ /^.\s*\}\s*else\s*$/ ||
> +		    $sline =~ /^.\s*else\s*\{\s*$/) {
>  			CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
>  		}
>  

      reply	other threads:[~2017-02-21  2:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20 12:16 [PATCH] checkpatch: remove false unbalanced braces warning Sven Eckelmann
2017-02-21  2:42 ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1487644978.2853.8.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sven@narfation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.