AutosarOS
assert.c
Go to the documentation of this file.
1 
14 #include "assert.h"
15 
16 extern void __assert(const char* file, const int line, const char* msg)
17 {
18 #ifdef ASSERT_BUFFER_SIZE
19 #ifdef STATIC_ASSERT_BUFFER
20  static char error[ASSERT_BUFFER_SIZE];
21 #else /* STATIC_ASSERT_BUFFER */
22  char error[ASSERT_BUFFER_SIZE];
23 #endif /* STATIC_ASSERT_BUFFER */
24 
25  char format[] = "Assertion failed in %s : Line %d : %s";
26 
27  // Disable warning because the address for error will always evaluate as 'true' if STATIC_ASSERT_BUFFER is defined
28 #pragma GCC diagnostic push
29 #pragma GCC diagnostic ignored "-Waddress"
30  if (strlen(msg) + strlen(format) + strlen(file) + 16 <= ASSERT_BUFFER_SIZE && error) {
31  sprintf(error, format, file, line, msg);
32  }
33 #pragma GCC diagnostic pop
34 
35 #endif /* ASSERT_BUFFER_SIZE */
36 
37 #ifdef BREAK_ON_ASSERT
38  asm("BREAK");
39 #endif /* BREAK_ON_ASSERT */
40 
41  abort();
42 }
__assert
void __assert(const char *file, const int line, const char *msg)
Definition: assert.c:16
assert.h
Assert macros and functions.
ASSERT_BUFFER_SIZE
#define ASSERT_BUFFER_SIZE
Definition: assert.h:65