logging: Add missing thread safety annotations
What changed, and why it matters
This commit adds compiler hints about which locks must not be held when calling two logging helper functions. It does not change any actual code behavior, memory layout, or runtime logic. The change helps automated tools detect potential future threading mistakes during development, but it does not fix an active bug by itself.
No immediate action required. Treat as normal code-quality/static-analysis improvement. Reviewers may verify that the annotations correctly describe the existing locking contract.
Security signals we found
Thread-safety annotation added to lock-protected member function
No functional code change
No runtime behavior change
No data flow or input validation change
Evidence from the diff
The patch adds EXCLUSIVE_LOCKS_REQUIRED(!m_cs) annotations to BCLog::Logger::NumConnections() and BCLog::Logger::AddCategoryLogLevel(). These are Clang thread-safety annotations telling the compiler/static analyzer that callers must not already hold m_cs because the functions acquire it internally with StdLockGuard. The function bodies are unchanged. This is a static-analysis/documentation improvement, not a runtime deadlock or vulnerability fix.
Changed components
src/logging.hBCLog::Logger::NumConnections()BCLog::Logger::AddCategoryLogLevel()Inspect captured patch +2 / −2
diff --git a/src/logging.h b/src/logging.h
index 803bdac1..1371c9a7 100644
--- a/src/logging.h
+++ b/src/logging.h
@@ -211,7 +211,7 @@ namespace BCLog {
m_print_callbacks.erase(it);
}
- size_t NumConnections()
+ size_t NumConnections() EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
{
StdLockGuard scoped_lock(m_cs);
return m_print_callbacks.size();
@@ -248,7 +248,7 @@ namespace BCLog {
StdLockGuard scoped_lock(m_cs);
m_category_log_levels = levels;
}
- void AddCategoryLogLevel(LogFlags category, Level level)
+ void AddCategoryLogLevel(LogFlags category, Level level) EXCLUSIVE_LOCKS_REQUIRED(!m_cs)
{
StdLockGuard scoped_lock(m_cs);
m_category_log_levels[category] = level;
Why this scored 16/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.