Skip to content

Commit

Permalink
Fix assert macro (do not display full path name in release mode)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogh333 committed Aug 28, 2024
1 parent 5161e2d commit 4d6091c
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ extern void assert(int cond, const char* msgStr);
#define ASSERT_WITH_MSG(cond, msg) assert(cond, msg)


#define _MAX_ASSERT_LENGTH_ 25
// Shortens a string literal by skipping some prefix
#define _SHORTEN_(strLiteral, size) \
(sizeof(strLiteral) > size \
? (strLiteral) + sizeof(strLiteral) - size \
: strLiteral \
)

#define _FILE_LINE_ __FILE__ ":" _TO_STR2_(__LINE__)

#define ASSERT(cond) assert((cond), _SHORTEN_( _FILE_LINE_, _MAX_ASSERT_LENGTH_))
#define ASSERT(cond) \
do { \
if (!(cond)) { \
PRINTF("ASSERT failed at "_FILE_LINE_"\n"); \
} \
assert((cond), NULL); \
} while (0)

#endif // H_CARDANO_APP_ASSERT

0 comments on commit 4d6091c

Please sign in to comment.