[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 11/21] checkpatch: Disallow glib asserts in main code
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 11/21] checkpatch: Disallow glib asserts in main code |
Date: |
Fri, 5 May 2017 12:13:27 +0200 |
From: "Dr. David Alan Gilbert" <address@hidden>
Glib commit a6a875068779 (from 2013) made many of the glib assert
macros non-fatal if a flag is set.
This causes two problems:
a) Compilers moan that your code is unsafe even though you've
put an assert in before the point of use.
b) Someone evil could, in a library, call
g_test_set_nonfatal_assertions() and cause our assertions in
important places not to fail and potentially allow memory overruns.
Ban most of the glib assertion functions (basically everything except
g_assert and g_assert_not_reached) except in tests/
This makes checkpatch gives an error such as:
ERROR: Use g_assert or g_assert_not_reached
#77: FILE: vl.c:4725:
+ g_assert_cmpstr("Chocolate", >, "Cheese");
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
scripts/checkpatch.pl | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f084542934..73cee81b79 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2571,6 +2571,27 @@ sub process {
if ($line =~ /\bbzero\(/) {
ERROR("use memset() instead of bzero()\n" . $herecurr);
}
+ my $non_exit_glib_asserts = qr{g_assert_cmpstr|
+ g_assert_cmpint|
+ g_assert_cmpuint|
+ g_assert_cmphex|
+ g_assert_cmpfloat|
+ g_assert_true|
+ g_assert_false|
+ g_assert_nonnull|
+ g_assert_null|
+ g_assert_no_error|
+ g_assert_error|
+ g_test_assert_expected_messages|
+ g_test_trap_assert_passed|
+ g_test_trap_assert_stdout|
+
g_test_trap_assert_stdout_unmatched|
+ g_test_trap_assert_stderr|
+
g_test_trap_assert_stderr_unmatched}x;
+ if ($realfile !~ /^tests\// &&
+ $line =~ /\b(?:$non_exit_glib_asserts)\(/) {
+ ERROR("Use g_assert or g_assert_not_reached\n".
$herecurr);
+ }
}
# If we have no input at all, then there is nothing to report on
--
2.12.2
- [Qemu-devel] [PULL 00/21] Misc patches for 2017-05-05, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 02/21] hw/i386: Build-time assertion on pc/q35 reset register being identical., Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 03/21] char: Fix removing wrong GSource that be found by fd_in_tag, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 05/21] use _Static_assert in QEMU_BUILD_BUG_ON, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 01/21] hw/i386: Use Rev3 FADT (ACPI 2.0) instead of Rev1 to improve guest OS support., Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 04/21] target/i386: Add GDB XML register description support, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 06/21] vl: deprecate the "-hdachs" option, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 07/21] scsi: avoid an off-by-one error in megasas_mmio_write, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 10/21] trace: add qemu mutex lock and unlock trace events, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 11/21] checkpatch: Disallow glib asserts in main code,
Paolo Bonzini <=
- [Qemu-devel] [PULL 13/21] dump: Acquire BQL around vm_start() in dump thread, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 08/21] sgabios: update for "fix wrong video attrs for int 10h, ah==13h", Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 12/21] hax: Fix memory mapping de-duplication logic, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 09/21] vmw_pvscsi: check message ring page count at initialisation, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 14/21] Fix the -accel parameter and the documentation for 'hax', Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 15/21] MAINTAINERS: Add "R:" tag for self-appointed reviewers, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 16/21] get_maintainer: Teach get_maintainer.pl about the new "R:" tag, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 19/21] get_maintainer: add subsystem to reviewer output, Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 17/21] get_maintainer: it's '--pattern-depth', not '-pattern-depth', Paolo Bonzini, 2017/05/05
- [Qemu-devel] [PULL 20/21] libvhost-user: replace vasprintf() to fix build, Paolo Bonzini, 2017/05/05