coverity: Fix assert model

This commit is contained in:
Andreas Schneider 2018-10-11 17:11:29 +02:00
parent 79578efd19
commit 2af6e52259
1 changed files with 32 additions and 8 deletions

View File

@ -43,9 +43,15 @@ void _assert_return_code(const LargestIntegralType result,
void _assert_string_equal(const char * const a, const char * const b, void _assert_string_equal(const char * const a, const char * const b,
const char * const file, const int line) const char * const file, const int line)
{ {
char ch;
int cmp; 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) { if (cmp != 0) {
__coverity_panic__(); __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, void _assert_string_not_equal(const char * const a, const char * const b,
const char *file, const int line) const char *file, const int line)
{ {
char ch;
int cmp; 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) { if (cmp == 0) {
__coverity_panic__(); __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 size_t size, const char* const file,
const int line) const int line)
{ {
unsigned char ch;
int cmp; 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) { if (cmp != 0) {
__coverity_panic__(); __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 size_t size, const char* const file,
const int line) const int line)
{ {
unsigned char ch;
int cmp; 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) { if (cmp == 0) {
__coverity_panic__(); __coverity_panic__();
} }
@ -108,9 +132,9 @@ void _assert_in_set(
const LargestIntegralType value, const LargestIntegralType values[], const LargestIntegralType value, const LargestIntegralType values[],
const size_t number_of_values, const char* const file, const int line) 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]) { if (value == values[i]) {
return; return;
} }
@ -122,9 +146,9 @@ void _assert_not_in_set(
const LargestIntegralType value, const LargestIntegralType values[], const LargestIntegralType value, const LargestIntegralType values[],
const size_t number_of_values, const char* const file, const int line) 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]) { if (value == values[i]) {
__coverity_panic__(); __coverity_panic__();
} }