From 788703574368a83eaecd689883a1e9bed32fb21d Mon Sep 17 00:00:00 2001 From: Chih-Hung Hsieh Date: Thu, 23 Apr 2020 14:39:18 -0700 Subject: [PATCH] Fix clang-analyzer-core.uninitialized.Branch warnings Bug: 154760495 Test: make with WITH_TIDY=1 and DEFAULT_GLOBAL_TIDY_CHECKS=clang-analyzer-core.uninitialized.Branch Change-Id: I569749166177c25e63b32fb468dccd13797acc05 --- tools/bit/adb.cpp | 2 +- tools/incident_section_gen/main.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/bit/adb.cpp b/tools/bit/adb.cpp index fa7d3d4031d41..f521a63255e17 100644 --- a/tools/bit/adb.cpp +++ b/tools/bit/adb.cpp @@ -200,7 +200,7 @@ skip_bytes(int fd, ssize_t size, char* scratch, int scratchSize) static int skip_unknown_field(int fd, uint64_t tag, char* scratch, int scratchSize) { - bool done; + bool done = false; int err; uint64_t size; switch (tag & 0x7) { diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp index 91f875ed99186..ba1267b28fbbc 100644 --- a/tools/incident_section_gen/main.cpp +++ b/tools/incident_section_gen/main.cpp @@ -368,10 +368,13 @@ static bool generatePrivacyFlags(const Descriptor* descriptor, const Destination // Don't generate a variable twice if (!hasDefaultFlags[i]) variableNames[fieldName] = false; } + // hasDefaultFlags[i] has been initialized in the above for-loop, + // but clang-tidy analyzer still report uninitized values. + // So we use NOLINT to suppress those false positives. bool allDefaults = true; for (size_t i=0; ierase(messageName); // erase the message type name when exit the message. @@ -384,7 +387,7 @@ static bool generatePrivacyFlags(const Descriptor* descriptor, const Destination printf("Privacy* %s[] = {\n", messageName.c_str()); for (size_t i=0; i