From 6466ced8f6e31e975a716694dc33db86169a1e2d Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 16 May 2017 16:31:31 -0700 Subject: [PATCH] logging: make LOG(FATAL) always run with the static analyzer. ::android::base::GetMinimumLogSeverity() is defined externally, so the static analyzer was allowed to assume that we continue executing after a LOG(FATAL). I manually audited all of the code I have access to, and the only "change the minimum log severity" statements I can see keep FATAL enabled (...and continuing after a FATAL is highly sketchy to me anyway). (I'm sure I tested this at some point in making the previous patch. I probably broke it in a refactor before sending it out for review; my bad. :) ) Bug: None Test: m without the static-analyzer builds; m with it yields fewer false positives. Change-Id: I216cd2034e1daa8d6f6c5e776f64b4cce88bb938 --- base/include/android-base/logging.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h index cf4a62467..548b286c4 100644 --- a/base/include/android-base/logging.h +++ b/base/include/android-base/logging.h @@ -176,15 +176,19 @@ struct LogAbortAfterFullExpr { // Provides an expression that evaluates to the truthiness of `x`, automatically // aborting if `c` is true. #define ABORT_AFTER_LOG_EXPR_IF(c, x) (((c) && ::android::base::LogAbortAfterFullExpr()) || (x)) +// Note to the static analyzer that we always execute FATAL logs in practice. +#define MUST_LOG_MESSAGE(severity) (SEVERITY_LAMBDA(severity) == ::android::base::FATAL) #else #define ABORT_AFTER_LOG_FATAL #define ABORT_AFTER_LOG_EXPR_IF(c, x) (x) +#define MUST_LOG_MESSAGE(severity) false #endif #define ABORT_AFTER_LOG_FATAL_EXPR(x) ABORT_AFTER_LOG_EXPR_IF(true, x) // Defines whether the given severity will be logged or silently swallowed. #define WOULD_LOG(severity) \ - UNLIKELY((SEVERITY_LAMBDA(severity)) >= ::android::base::GetMinimumLogSeverity()) + (UNLIKELY((SEVERITY_LAMBDA(severity)) >= ::android::base::GetMinimumLogSeverity()) || \ + MUST_LOG_MESSAGE(severity)) // Get an ostream that can be used for logging at the given severity and to the default // destination.