[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 41/41] checkpatch: Detect newlines in error_report an
From: |
Markus Armbruster |
Subject: |
[Qemu-devel] [PULL 41/41] checkpatch: Detect newlines in error_report and other error functions |
Date: |
Wed, 13 Jan 2016 16:43:39 +0100 |
From: "Jason J. Herne" <address@hidden>
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 <address@hidden>
Message-Id: <address@hidden>
[Rephrased "Error function text" to "Error messages", dropped
error_vprintf, error_printf, error_printf from $qemu_error_funcs,
because they may legitimately print newlines]
Signed-off-by: Markus Armbruster <address@hidden>
---
scripts/checkpatch.pl | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index efca817..257126f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2498,6 +2498,42 @@ sub process {
WARN("use QEMU instead of Qemu or QEmu\n" . $herecurr);
}
+# Qemu error function tests
+
+ # Find newlines in error messages
+ my $qemu_error_funcs = qr{error_setg|
+ error_setg_errno|
+ error_setg_win32|
+ error_set|
+ error_vreport|
+ error_report}x;
+
+ if ($rawline =~ /\b(?:$qemu_error_funcs)\s*\(\s*\".*\\n/) {
+ WARN("Error messages should not contain newlines\n" .
$herecurr);
+ }
+
+ # Continue checking for error messages 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 messages 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);
--
2.4.3
- [Qemu-devel] [PULL 19/41] error: Use error_report_err() instead of monitor_printf(), (continued)
- [Qemu-devel] [PULL 19/41] error: Use error_report_err() instead of monitor_printf(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 35/41] pci-assign: Clean up "Failed to assign" error messages, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 06/41] arm_mptimer: Don't use hw_error() in realize() method, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 14/41] isa: Clean up inappropriate hw_error(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 23/41] qemu-nbd: Clean up "Failed to load snapshot" error message, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 12/41] isa: Trivially convert remaining PCI-ISA bridges to realize(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 16/41] xen-hvm: Mark inappropriate error handling FIXME, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 25/41] error: New error_prepend(), error_reportf_err(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 10/41] hw/arm/virt: Fix property "gic-version" error handling, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 29/41] spapr: Use error_reportf_err(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 41/41] checkpatch: Detect newlines in error_report and other error functions,
Markus Armbruster <=
- [Qemu-devel] [PULL 33/41] vmdk: Clean up control flow in vmdk_parse_extents() a bit, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 26/41] error: Don't decorate original error message when adding to it, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 32/41] error: Strip trailing '\n' from error string arguments (again), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 40/41] error: Consistently name Error * objects err, and not errp, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 22/41] block: Clean up "Could not create temporary overlay" error message, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 27/41] error: Use error_reportf_err() where it makes obvious sense, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 30/41] migration: Use error_reportf_err() instead of monitor_printf(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 34/41] vmdk: Clean up "Invalid extent lines" error message, Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 39/41] s390/sclp: Simplify control flow in sclp_realize(), Markus Armbruster, 2016/01/13
- [Qemu-devel] [PULL 37/41] error: Clean up errors with embedded newlines (again), Markus Armbruster, 2016/01/13