Skip to content

Commit c425acd

Browse files
plafosseclaude
andcommitted
Wrap LogTrace FV/F functions with BN_ENABLE_LOG_TRACE guard
The *FV and *F variants were unconditionally calling fmt::vformat (allocating/formatting strings) even when trace logging was compiled out, since only the underlying LogTrace* callees were guarded. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 52014ae commit c425acd

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

binaryninjaapi.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,9 @@ namespace BinaryNinja {
944944
template<typename... T>
945945
void LogTraceF(fmt::format_string<T...> format, T&&... args)
946946
{
947+
#ifdef BN_ENABLE_LOG_TRACE
947948
LogTraceFV(format, fmt::make_format_args(args...));
949+
#endif
948950
}
949951

950952
/*! LogDebug only writes text to the error console if the console is set to log level: DebugLog
@@ -1058,7 +1060,9 @@ namespace BinaryNinja {
10581060
template <typename... T>
10591061
void LogTraceForExceptionF(const std::exception& e, fmt::format_string<T...> format, T&&... args)
10601062
{
1063+
#ifdef BN_ENABLE_LOG_TRACE
10611064
LogTraceForExceptionFV(e, format, fmt::make_format_args(args...));
1065+
#endif
10621066
}
10631067

10641068
/*! LogDebugForExceptionF only writes text to the error console if the console is set to log level: DebugLog
@@ -1175,7 +1179,9 @@ namespace BinaryNinja {
11751179
template <typename... T>
11761180
void LogTraceWithStackTraceF(fmt::format_string<T...> format, T&&... args)
11771181
{
1182+
#ifdef BN_ENABLE_LOG_TRACE
11781183
LogTraceWithStackTraceFV(format, fmt::make_format_args(args...));
1184+
#endif
11791185
}
11801186

11811187
/*! LogDebugWithStackTraceF only writes text to the error console if the console is set to log level: DebugLog
@@ -1581,7 +1587,9 @@ namespace BinaryNinja {
15811587
template<typename... T>
15821588
void LogTraceF(fmt::format_string<T...> format, T&&... args)
15831589
{
1590+
#ifdef BN_ENABLE_LOG_TRACE
15841591
LogTraceFV(format, fmt::make_format_args(args...));
1592+
#endif
15851593
}
15861594

15871595
/*! LogDebug only writes text to the error console if the console is set to log level: DebugLog
@@ -1682,7 +1690,9 @@ namespace BinaryNinja {
16821690
template <typename... T>
16831691
void LogTraceForExceptionF(const std::exception& e, fmt::format_string<T...> format, T&&... args)
16841692
{
1693+
#ifdef BN_ENABLE_LOG_TRACE
16851694
LogTraceForExceptionFV(e, format, fmt::make_format_args(args...));
1695+
#endif
16861696
}
16871697

16881698
/*! LogDebugForExceptionF only writes text to the error console if the console is set to log level:
@@ -1785,7 +1795,9 @@ namespace BinaryNinja {
17851795
template <typename... T>
17861796
void LogTraceWithStackTraceF(fmt::format_string<T...> format, T&&... args)
17871797
{
1798+
#ifdef BN_ENABLE_LOG_TRACE
17881799
LogTraceWithStackTraceFV(format, fmt::make_format_args(args...));
1800+
#endif
17891801
}
17901802

17911803
/*! LogDebugWithStackTraceF only writes text to the error console if the console is set to log level:

log.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,10 @@ void BinaryNinja::LogFV(BNLogLevel level, fmt::string_view format, fmt::format_a
408408

409409
void BinaryNinja::LogTraceFV(fmt::string_view format, fmt::format_args args)
410410
{
411+
#ifdef BN_ENABLE_LOG_TRACE
411412
std::string value = fmt::vformat(format, args);
412413
LogTrace("%s", value.c_str());
414+
#endif
413415
}
414416

415417

@@ -423,8 +425,10 @@ void BinaryNinja::LogForExceptionFV(
423425

424426
void BinaryNinja::LogTraceForExceptionFV(const std::exception& e, fmt::string_view format, fmt::format_args args)
425427
{
428+
#ifdef BN_ENABLE_LOG_TRACE
426429
std::string value = fmt::vformat(format, args);
427430
LogTraceForException(e, "%s", value.c_str());
431+
#endif
428432
}
429433

430434

@@ -437,8 +441,10 @@ void BinaryNinja::LogWithStackTraceFV(BNLogLevel level, fmt::string_view format,
437441

438442
void BinaryNinja::LogTraceWithStackTraceFV(fmt::string_view format, fmt::format_args args)
439443
{
444+
#ifdef BN_ENABLE_LOG_TRACE
440445
std::string value = fmt::vformat(format, args);
441446
LogTraceWithStackTrace("%s", value.c_str());
447+
#endif
442448
}
443449

444450

@@ -700,8 +706,10 @@ void Logger::LogFV(BNLogLevel level, fmt::string_view format, fmt::format_args a
700706

701707
void Logger::LogTraceFV(fmt::string_view format, fmt::format_args args)
702708
{
709+
#ifdef BN_ENABLE_LOG_TRACE
703710
std::string value = fmt::vformat(format, args);
704711
LogTrace("%s", value.c_str());
712+
#endif
705713
}
706714

707715

@@ -715,8 +723,10 @@ void Logger::LogForExceptionFV(
715723

716724
void Logger::LogTraceForExceptionFV(const std::exception& e, fmt::string_view format, fmt::format_args args)
717725
{
726+
#ifdef BN_ENABLE_LOG_TRACE
718727
std::string value = fmt::vformat(format, args);
719728
LogTraceForException(e, "%s", value.c_str());
729+
#endif
720730
}
721731

722732

@@ -729,8 +739,10 @@ void Logger::LogWithStackTraceFV(BNLogLevel level, fmt::string_view format, fmt:
729739

730740
void Logger::LogTraceWithStackTraceFV(fmt::string_view format, fmt::format_args args)
731741
{
742+
#ifdef BN_ENABLE_LOG_TRACE
732743
std::string value = fmt::vformat(format, args);
733744
LogTraceWithStackTrace("%s", value.c_str());
745+
#endif
734746
}
735747

736748

0 commit comments

Comments
 (0)