tests/qtest/npcm7xx_pwm-test.c: Avoid g_assert_true() for non-test assertions
commit302585450c667cac06371a80446eedf670d2d510
authorPeter Maydell <peter.maydell@linaro.org>
Wed, 5 May 2021 13:55:16 +0000 (5 14:55 +0100)
committerThomas Huth <thuth@redhat.com>
Fri, 14 May 2021 10:28:01 +0000 (14 12:28 +0200)
tree632c2552ea7577064d96929aa2660b91a1ace2f7
parent423dbce5a2bf392bf9f6ab655a672d3d6654c325
tests/qtest/npcm7xx_pwm-test.c: Avoid g_assert_true() for non-test assertions

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 144234014423411442343144234414423451442346
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