Skip to content

Commit

Permalink
fix: use a function-like macro to set yr_debug_indent
Browse files Browse the repository at this point in the history
Drawback of this solution is a compiler warning about the unused
variable for non-debug builds. But this should not be a performance
penalty because the unused variable should be optimized away by the
compiler.
  • Loading branch information
gremat committed Jan 17, 2025
1 parent 5748522 commit 214c597
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions libyara/exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,14 @@ static void exception_handler(int sig, siginfo_t * info, void *context)

// Keep debug output indentation level consistent
#if 0 == YR_DEBUG_VERBOSITY
#define YR_DEBUG_INDENT_RESET_INIT
#define YR_DEBUG_INDENT_RESET_RESTORE
#define YR_DEBUG_INDENT_INITIAL 0
#define YR_DEBUG_INDENT_SET(x) ;
#else
extern YR_TLS int yr_debug_indent;
// Ugly, but unfortunately cannot use ifdef macros inside a macro
#define YR_DEBUG_INDENT_RESET_INIT int yr_debug_indent_before_jump = yr_debug_indent;
#define YR_DEBUG_INDENT_RESET_RESTORE yr_debug_indent = yr_debug_indent_before_jump;
#define YR_DEBUG_INDENT_INITIAL yr_debug_indent
#define YR_DEBUG_INDENT_SET(x) yr_debug_indent = (x);

#endif

typedef struct sigaction sa;
Expand All @@ -255,7 +256,7 @@ typedef struct sigaction sa;
exception_handler_usecount++; \
pthread_mutex_unlock(&exception_handler_mutex); \
/* Save the current debug indentation level before the jump. */ \
YR_DEBUG_INDENT_RESET_INIT \
int yr_debug_indent_before_jump = YR_DEBUG_INDENT_INITIAL; \
jumpinfo ji; \
ji.memfault_from = 0; \
ji.memfault_to = 0; \
Expand All @@ -270,7 +271,7 @@ typedef struct sigaction sa;
else \
{ \
/* Restore debug output indentation in case of failure */ \
YR_DEBUG_INDENT_RESET_RESTORE \
YR_DEBUG_INDENT_SET(yr_debug_indent_before_jump); \
\
_catch_clause_ \
} \
Expand Down

0 comments on commit 214c597

Please sign in to comment.