qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 8/8] checkpatch: handle token pasting better
Date: Fri,  6 Jul 2018 19:14:28 +0200	[thread overview]
Message-ID: <1530897268-22932-9-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1530897268-22932-1-git-send-email-pbonzini@redhat.com>

The mechanism to find possible type tokens can sometimes be confused and go into an
infinite loop.  This happens for example in QEMU for a line that looks like

         uint## BITS ##_t S = _S, T = _T;                            \
         uint## BITS ##_t as, at, xs, xt, xd;                        \

Because the token pasting operator does not have a space before _t, it does not
match $notPermitted.  However, (?x) is turned on in the regular expression for
modifiers, and thus ##_t matches the empty string.  As a result, annotate_values
goes in an infinite loop.

The solution is simply to remove token pasting operators from the string before
looking for modifiers.  In the example above, the string uintBITS_t will be
evaluated as a candidate modifier.  This is not optimal, but it works as long
as people do not write things like a##s##m, and it fits nicely into sub
possible.

For a similar reason, \# should be rejected always, even if it is not
at end of line or followed by whitespace.

The same patch was sent to the Linux kernel mailing list.

Reported-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 scripts/checkpatch.pl | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 223681b..42e1c50 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1132,11 +1132,10 @@ sub possible {
 			case|
 			else|
 			asm|__asm__|
-			do|
-			\#|
-			\#\#
+			do
 		)(?:\s|$)|
-		^(?:typedef|struct|enum)\b
+		^(?:typedef|struct|enum)\b|
+		^\#
 	    )}x;
 	warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
 	if ($possible !~ $notPermitted) {
@@ -1146,7 +1145,7 @@ sub possible {
 		if ($possible =~ /^\s*$/) {
 
 		} elsif ($possible =~ /\s/) {
-			$possible =~ s/\s*$Type\s*//g;
+			$possible =~ s/\s*(?:$Type|\#\#)\s*//g;
 			for my $modifier (split(' ', $possible)) {
 				if ($modifier !~ $notPermitted) {
 					warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
-- 
1.8.3.1

  parent reply	other threads:[~2018-07-06 17:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-06 17:14 [Qemu-devel] [PULL 0/8] Bug fixes for 2018-07-06 Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 1/8] pr-helper: avoid error on PR IN command with zero request size Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 2/8] pr-helper: Rework socket path handling Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 3/8] qtest: Use cpu address space instead of system memory Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 4/8] i386: fix '-cpu ?' output for host cpu type Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 5/8] qemu-char: check errno together with ret < 0 Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 6/8] pr-manager-helper: fix memory leak on event Paolo Bonzini
2018-07-06 17:14 ` [Qemu-devel] [PULL 7/8] ioapic: remove useless lower bounds check Paolo Bonzini
2018-07-06 17:14 ` Paolo Bonzini [this message]
2018-07-06 18:05 ` [Qemu-devel] [PULL 0/8] Bug fixes for 2018-07-06 Peter Maydell

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=1530897268-22932-9-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).