[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/20] tests/qtest/npcm7xx_pwm-test.c: Avoid g_assert_true() for n
From: |
Thomas Huth |
Subject: |
[PULL 10/20] tests/qtest/npcm7xx_pwm-test.c: Avoid g_assert_true() for non-test assertions |
Date: |
Fri, 14 May 2021 14:15:08 +0200 |
From: Peter Maydell <peter.maydell@linaro.org>
In the glib API, the distinction between g_assert() and
g_assert_true() is that the former is for "bug, terminate the
application" and the latter is for "test check, on failure either
terminate or just mark the testcase as failed". For QEMU, g_assert()
is always fatal, so code can assume that if the assertion fails
execution does not proceed, but this is not true of g_assert_true().
In npcm7xx_pwm-test, the pwm_index() and pwm_module_index() functions
include some assertions that are just guarding against possible bugs
in the test code that might lead us to out-of-bounds array accesses.
These should use g_assert() because they aren't part of what the test
is testing and the code does not correctly handle the case where the
condition was false.
This fixes some Coverity issues where Coverity knows that
g_assert_true() can continue when the condition is false and
complains about the possible array overrun at various callsites.
Fixes: Coverity CID 1442340, 1442341, 1442343, 1442344, 1442345, 1442346
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Reviewed-by: Havard Skinnemoen <hskinnemoen@google.com>
Message-Id: <20210505135516.21097-1-peter.maydell@linaro.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/npcm7xx_pwm-test.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/qtest/npcm7xx_pwm-test.c b/tests/qtest/npcm7xx_pwm-test.c
index bd15a1c294..a54fd70d27 100644
--- a/tests/qtest/npcm7xx_pwm-test.c
+++ b/tests/qtest/npcm7xx_pwm-test.c
@@ -201,7 +201,7 @@ static int pwm_module_index(const PWMModule *module)
{
ptrdiff_t diff = module - pwm_module_list;
- g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_module_list));
+ g_assert(diff >= 0 && diff < ARRAY_SIZE(pwm_module_list));
return diff;
}
@@ -211,7 +211,7 @@ static int pwm_index(const PWM *pwm)
{
ptrdiff_t diff = pwm - pwm_list;
- g_assert_true(diff >= 0 && diff < ARRAY_SIZE(pwm_list));
+ g_assert(diff >= 0 && diff < ARRAY_SIZE(pwm_list));
return diff;
}
--
2.27.0
- [PULL 00/20] CI, qtest, and misc patches, Thomas Huth, 2021/05/14
- [PULL 02/20] gitlab-ci: Replace YAML anchors by extends (container_job), Thomas Huth, 2021/05/14
- [PULL 01/20] tests/docker/dockerfiles: Add ccache to containers where it was missing, Thomas Huth, 2021/05/14
- [PULL 03/20] gitlab-ci: Replace YAML anchors by extends (native_build_job), Thomas Huth, 2021/05/14
- [PULL 04/20] gitlab-ci: Replace YAML anchors by extends (native_test_job), Thomas Huth, 2021/05/14
- [PULL 05/20] libqos/qgraph: fix "UNAVAILBLE" typo, Thomas Huth, 2021/05/14
- [PULL 07/20] libqtest: refuse QTEST_QEMU_BINARY=qemu-kvm, Thomas Huth, 2021/05/14
- [PULL 06/20] docs/devel/qgraph: add troubleshooting information, Thomas Huth, 2021/05/14
- [PULL 10/20] tests/qtest/npcm7xx_pwm-test.c: Avoid g_assert_true() for non-test assertions,
Thomas Huth <=
- [PULL 11/20] tests/migration-test: Fix "true" vs true, Thomas Huth, 2021/05/14
- [PULL 09/20] tests/qtest/ahci-test.c: Calculate iso_size with 64-bit arithmetic, Thomas Huth, 2021/05/14
- [PULL 08/20] util/compatfd.c: Replaced a malloc call with g_malloc., Thomas Huth, 2021/05/14
- [PULL 13/20] tests/qtest/rtc-test: Remove pointless NULL check, Thomas Huth, 2021/05/14
- [PULL 17/20] configure: Poison all current target-specific #defines, Thomas Huth, 2021/05/14
- [PULL 14/20] tests: Avoid side effects inside g_assert() arguments, Thomas Huth, 2021/05/14
- [PULL 15/20] include/sysemu: Poison all accelerator CONFIG switches in common code, Thomas Huth, 2021/05/14
- [PULL 16/20] migration: Move populate_vfio_info() into a separate file, Thomas Huth, 2021/05/14