aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-10-11 17:11:29 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-10-11 17:22:56 +0200
commit20f40cde88bd1ec3f508431a76cfe08723e2dd2a (patch)
tree731944c7806967a4bc5f9b77b885e0571a53d704
parent17e3b51db1a53416ddf5193beee7c7f17d1629d4 (diff)
downloadcmocka-20f40cde88bd1ec3f508431a76cfe08723e2dd2a.tar.gz
cmocka-20f40cde88bd1ec3f508431a76cfe08723e2dd2a.tar.xz
cmocka-20f40cde88bd1ec3f508431a76cfe08723e2dd2a.zip
coverity: Fix assert model
-rw-r--r--coverity/coverity_assert_model.c71
1 files changed, 58 insertions, 13 deletions
diff --git a/coverity/coverity_assert_model.c b/coverity/coverity_assert_model.c
index 9bbb9f7..76baeab 100644
--- a/coverity/coverity_assert_model.c
+++ b/coverity/coverity_assert_model.c
@@ -1,24 +1,31 @@
#define LargestIntegralType unsigned long long
+
void _assert_true(const LargestIntegralType result,
const char* const expression,
const char * const file, const int line)
{
- __coverity_panic__();
+ if (!result) {
+ __coverity_panic__();
+ }
}
void _assert_int_equal(
const LargestIntegralType a, const LargestIntegralType b,
const char * const file, const int line)
{
- __coverity_panic__();
+ if (a != b) {
+ __coverity_panic__();
+ }
}
void _assert_int_not_equal(
const LargestIntegralType a, const LargestIntegralType b,
const char * const file, const int line)
{
- __coverity_panic__();
+ if (a == b) {
+ __coverity_panic__();
+ }
}
void _assert_return_code(const LargestIntegralType result,
@@ -28,60 +35,98 @@ void _assert_return_code(const LargestIntegralType result,
const char * const file,
const int line)
{
- __coverity_panic__();
+ if (result != 0) {
+ __coverity_panic__();
+ }
}
void _assert_string_equal(const char * const a, const char * const b,
const char * const file, const int line)
{
- __coverity_panic__();
+ int cmp;
+
+ cmp = __coverity_strcmp(a, b);
+ if (cmp != 0) {
+ __coverity_panic__();
+ }
}
void _assert_string_not_equal(const char * const a, const char * const b,
const char *file, const int line)
{
- __coverity_panic__();
+ int cmp;
+
+ cmp = __coverity_strcmp(a, b);
+ if (cmp == 0) {
+ __coverity_panic__();
+ }
}
void _assert_memory_equal(const void * const a, const void * const b,
const size_t size, const char* const file,
const int line)
{
- __coverity_panic__();
+ int cmp;
+
+ cmp = memcmp(a, b, size);
+ if (cmp != 0) {
+ __coverity_panic__();
+ }
}
void _assert_memory_not_equal(const void * const a, const void * const b,
const size_t size, const char* const file,
const int line)
{
- __coverity_panic__();
+ int cmp;
+
+ cmp = memcmp(a, b, size);
+ if (cmp == 0) {
+ __coverity_panic__();
+ }
}
void _assert_in_range(
const LargestIntegralType value, const LargestIntegralType minimum,
const LargestIntegralType maximum, const char* const file, const int line)
{
- __coverity_panic__();
+ if (value < minimum || value > maximum) {
+ __coverity_panic__();
+ }
}
void _assert_not_in_range(
const LargestIntegralType value, const LargestIntegralType minimum,
const LargestIntegralType maximum, const char* const file, const int line)
{
- __coverity_panic__();
+ if (value > minimum && value < maximum) {
+ __coverity_panic__();
+ }
}
void _assert_in_set(
const LargestIntegralType value, const LargestIntegralType values[],
const size_t number_of_values, const char* const file, const int line)
{
- __coverity_panic__();
+ int i;
+
+ if (i = 0; i < number_of_values; i++) {
+ if (value == values[i]) {
+ return;
+ }
+ }
+ __coverity_panic__();
}
void _assert_not_in_set(
const LargestIntegralType value, const LargestIntegralType values[],
const size_t number_of_values, const char* const file, const int line)
{
- __coverity_panic__();
-}
+ int i;
+ if (i = 0; i < number_of_values; i++) {
+ if (value == values[i]) {
+ __coverity_panic__();
+ }
+ }
+}