From 6cecd20e259b09dd09a78d0f1b742be41e715806 Mon Sep 17 00:00:00 2001 From: George Burgess IV Date: Tue, 22 Aug 2017 10:37:54 -0700 Subject: Work around a bug in clang's static analyzer Due to https://bugs.llvm.org/show_bug.cgi?id=34198, clang's static analyzer emits diagnostics about leaking `container`. Doing this assignment in two steps works around this, and shouldn't cause these issues. --- src/google/protobuf/metadata_lite.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/google/protobuf/metadata_lite.h') diff --git a/src/google/protobuf/metadata_lite.h b/src/google/protobuf/metadata_lite.h index 64fde0c6..6022be92 100644 --- a/src/google/protobuf/metadata_lite.h +++ b/src/google/protobuf/metadata_lite.h @@ -150,8 +150,11 @@ class InternalMetadataWithArenaBase { GOOGLE_ATTRIBUTE_NOINLINE T* mutable_unknown_fields_slow() { Arena* my_arena = arena(); Container* container = Arena::Create(my_arena); + // Two-step assignment works around a bug in clang's static analyzer: + // https://bugs.llvm.org/show_bug.cgi?id=34198. + ptr_ = container; ptr_ = reinterpret_cast( - reinterpret_cast(container) | kTagContainer); + reinterpret_cast(ptr_) | kTagContainer); container->arena = my_arena; return &(container->unknown_fields); } -- cgit v1.2.3