From 2af6e52259bfd0cc7711aefbc20ce45fa90f788d Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Thu, 11 Oct 2018 17:11:29 +0200 Subject: [PATCH] coverity: Fix assert model --- coverity/coverity_assert_model.c | 40 +++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/coverity/coverity_assert_model.c b/coverity/coverity_assert_model.c index 76baeab..7ff64d8 100644 --- a/coverity/coverity_assert_model.c +++ b/coverity/coverity_assert_model.c @@ -43,9 +43,15 @@ void _assert_return_code(const LargestIntegralType result, void _assert_string_equal(const char * const a, const char * const b, const char * const file, const int line) { + char ch; int cmp; - cmp = __coverity_strcmp(a, b); + __coverity_weak_guard_sink__(a, b); + __coverity_weak_guard_sink__(b, a); + + ch = *((char *)a); + ch = *((char *)b); + if (cmp != 0) { __coverity_panic__(); } @@ -54,9 +60,15 @@ void _assert_string_equal(const char * const a, const char * const b, void _assert_string_not_equal(const char * const a, const char * const b, const char *file, const int line) { + char ch; int cmp; - cmp = __coverity_strcmp(a, b); + __coverity_weak_guard_sink__(a, b); + __coverity_weak_guard_sink__(b, a); + + ch = *((char *)a); + ch = *((char *)b); + if (cmp == 0) { __coverity_panic__(); } @@ -66,9 +78,15 @@ void _assert_memory_equal(const void * const a, const void * const b, const size_t size, const char* const file, const int line) { + unsigned char ch; int cmp; - cmp = memcmp(a, b, size); + __coverity_weak_guard_sink__(a, b); + __coverity_weak_guard_sink__(b, a); + + ch = *((unsigned char *)a); + ch = *((unsigned char *)b); + if (cmp != 0) { __coverity_panic__(); } @@ -78,9 +96,15 @@ void _assert_memory_not_equal(const void * const a, const void * const b, const size_t size, const char* const file, const int line) { + unsigned char ch; int cmp; - cmp = memcmp(a, b, size); + __coverity_weak_guard_sink__(a, b); + __coverity_weak_guard_sink__(b, a); + + ch = *((unsigned char *)a); + ch = *((unsigned char *)b); + if (cmp == 0) { __coverity_panic__(); } @@ -108,9 +132,9 @@ void _assert_in_set( const LargestIntegralType value, const LargestIntegralType values[], const size_t number_of_values, const char* const file, const int line) { - int i; + size_t i; - if (i = 0; i < number_of_values; i++) { + for (i = 0; i < number_of_values; i++) { if (value == values[i]) { return; } @@ -122,9 +146,9 @@ void _assert_not_in_set( const LargestIntegralType value, const LargestIntegralType values[], const size_t number_of_values, const char* const file, const int line) { - int i; + size_t i; - if (i = 0; i < number_of_values; i++) { + for (i = 0; i < number_of_values; i++) { if (value == values[i]) { __coverity_panic__(); }