From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7SSy-0003A8-F0 for qemu-devel@nongnu.org; Fri, 11 Dec 2015 13:30:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a7SSv-0005oZ-6S for qemu-devel@nongnu.org; Fri, 11 Dec 2015 13:30:52 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:49400) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a7SSu-0005oU-U8 for qemu-devel@nongnu.org; Fri, 11 Dec 2015 13:30:49 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 11 Dec 2015 11:30:48 -0700 Received: from b03cxnp08028.gho.boulder.ibm.com (b03cxnp08028.gho.boulder.ibm.com [9.17.130.20]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 2DFD019D8045 for ; Fri, 11 Dec 2015 11:18:51 -0700 (MST) Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tBBIUkvm16253002 for ; Fri, 11 Dec 2015 11:30:46 -0700 Received: from d03av05.boulder.ibm.com (localhost [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tBBIUjG2013315 for ; Fri, 11 Dec 2015 11:30:45 -0700 From: "Jason J. Herne" Date: Fri, 11 Dec 2015 13:30:42 -0500 Message-Id: <1449858642-24267-1-git-send-email-jjherne@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2] checkpatch: Detect newlines in error_report and other error functions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: blauwirbel@gmail.com, cornelia.huck@de.ibm.com, qemu-devel@nongnu.org Cc: "Jason J. Herne" We don't want newlines embedded in error messages. This seems to be a common problem with new code so let's try to catch it with checkpatch. This will not catch cases where newlines are inserted into the middle of an existing multi-line statement. But those cases should be rare. Signed-off-by: Jason J. Herne --- scripts/checkpatch.pl | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b0f6e11..51ea667 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2511,6 +2511,45 @@ sub process { WARN("use QEMU instead of Qemu or QEmu\n" . $herecurr); } +# Qemu error function tests + + # Find newlines in error function text + my $qemu_error_funcs = qr{error_setg| + error_setg_errno| + error_setg_win32| + error_set| + error_vprintf| + error_printf| + error_printf_unless_qmp| + error_vreport| + error_report}x; + + if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(\s*\".*\\n/) { + WARN("Error function text should not contain newlines\n" . $herecurr); + } + + # Continue checking for error function text that contains newlines. This + # check handles cases where string literals are spread over multiple lines. + # Example: + # error_report("Error msg line #1" + # "Error msg line #2\n"); + my $quoted_newline_regex = qr{\+\s*\".*\\n.*\"}; + my $continued_str_literal = qr{\+\s*\".*\"}; + + if ($rawline =~ /$quoted_newline_regex/) { + # Backtrack to first line that does not contain only a quoted literal + # and assume that it is the start of the statement. + my $i = $linenr - 2; + + while (($i >= 0) & $rawlines[$i] =~ /$continued_str_literal/) { + $i--; + } + + if ($rawlines[$i] =~ /\b(?:$qemu_error_funcs)\s*\(/) { + WARN("Error function text should not contain newlines\n" . $herecurr); + } + } + # check for non-portable ffs() calls that have portable alternatives in QEMU if ($line =~ /\bffs\(/) { ERROR("use ctz32() instead of ffs()\n" . $herecurr); -- 1.9.1