James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame^] | 1 | From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | From: Peter Johnson <johnson.peter@gmail.com> |
| 3 | Date: Sat, 10 Jun 2023 15:00:20 -0700 |
| 4 | Subject: [PATCH 03/11] Fix maybe-uninitialized warnings |
| 5 | |
| 6 | --- |
| 7 | src/google/protobuf/arena.cc | 6 +++--- |
| 8 | src/google/protobuf/arena_impl.h | 4 ++-- |
| 9 | src/google/protobuf/extension_set_inl.h | 2 +- |
| 10 | .../protobuf/generated_message_tctable_lite.cc | 16 ++++++++-------- |
| 11 | src/google/protobuf/io/coded_stream.cc | 2 +- |
| 12 | 5 files changed, 15 insertions(+), 15 deletions(-) |
| 13 | |
| 14 | diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc |
| 15 | index 6ba508a5f0f3436d52ccc326cc932ceed3cd79fa..194404213ee5f6ad05b1e01f2bff23859d60dc56 100644 |
| 16 | --- a/src/google/protobuf/arena.cc |
| 17 | +++ b/src/google/protobuf/arena.cc |
| 18 | @@ -411,7 +411,7 @@ uint64_t ThreadSafeArena::Reset() { |
| 19 | std::pair<void*, SerialArena::CleanupNode*> |
| 20 | ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, |
| 21 | const std::type_info* type) { |
| 22 | - SerialArena* arena; |
| 23 | + SerialArena* arena = nullptr; |
| 24 | if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && |
| 25 | GetSerialArenaFast(&arena))) { |
| 26 | return arena->AllocateAlignedWithCleanup(n, alloc_policy_.get()); |
| 27 | @@ -421,7 +421,7 @@ ThreadSafeArena::AllocateAlignedWithCleanup(size_t n, |
| 28 | } |
| 29 | |
| 30 | void ThreadSafeArena::AddCleanup(void* elem, void (*cleanup)(void*)) { |
| 31 | - SerialArena* arena; |
| 32 | + SerialArena* arena = nullptr; |
| 33 | if (PROTOBUF_PREDICT_FALSE(!GetSerialArenaFast(&arena))) { |
| 34 | arena = GetSerialArenaFallback(&thread_cache()); |
| 35 | } |
| 36 | @@ -433,7 +433,7 @@ void* ThreadSafeArena::AllocateAlignedFallback(size_t n, |
| 37 | const std::type_info* type) { |
| 38 | if (alloc_policy_.should_record_allocs()) { |
| 39 | alloc_policy_.RecordAlloc(type, n); |
| 40 | - SerialArena* arena; |
| 41 | + SerialArena* arena = nullptr; |
| 42 | if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { |
| 43 | return arena->AllocateAligned(n, alloc_policy_.get()); |
| 44 | } |
| 45 | diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h |
| 46 | index 76727688b558354be18f0c6576db1d4619348ef4..8af70c48f13feece7cf8580e71845ec267ddaddb 100644 |
| 47 | --- a/src/google/protobuf/arena_impl.h |
| 48 | +++ b/src/google/protobuf/arena_impl.h |
| 49 | @@ -482,7 +482,7 @@ class PROTOBUF_EXPORT ThreadSafeArena { |
| 50 | |
| 51 | template <AllocationClient alloc_client = AllocationClient::kDefault> |
| 52 | void* AllocateAligned(size_t n, const std::type_info* type) { |
| 53 | - SerialArena* arena; |
| 54 | + SerialArena* arena = nullptr; |
| 55 | if (PROTOBUF_PREDICT_TRUE(!alloc_policy_.should_record_allocs() && |
| 56 | GetSerialArenaFast(&arena))) { |
| 57 | return arena->AllocateAligned<alloc_client>(n, AllocPolicy()); |
| 58 | @@ -492,7 +492,7 @@ class PROTOBUF_EXPORT ThreadSafeArena { |
| 59 | } |
| 60 | |
| 61 | void ReturnArrayMemory(void* p, size_t size) { |
| 62 | - SerialArena* arena; |
| 63 | + SerialArena* arena = nullptr; |
| 64 | if (PROTOBUF_PREDICT_TRUE(GetSerialArenaFast(&arena))) { |
| 65 | arena->ReturnArrayMemory(p, size); |
| 66 | } |
| 67 | diff --git a/src/google/protobuf/extension_set_inl.h b/src/google/protobuf/extension_set_inl.h |
| 68 | index e4e711721d4d8690e1e87fc8e31df1b5836d4fd7..50c04cd41feccf6cb5fda2740d6d4adb874645d7 100644 |
| 69 | --- a/src/google/protobuf/extension_set_inl.h |
| 70 | +++ b/src/google/protobuf/extension_set_inl.h |
| 71 | @@ -206,7 +206,7 @@ const char* ExtensionSet::ParseMessageSetItemTmpl( |
| 72 | const char* ptr, const Msg* extendee, internal::InternalMetadata* metadata, |
| 73 | internal::ParseContext* ctx) { |
| 74 | std::string payload; |
| 75 | - uint32_t type_id; |
| 76 | + uint32_t type_id = 0; |
| 77 | enum class State { kNoTag, kHasType, kHasPayload, kDone }; |
| 78 | State state = State::kNoTag; |
| 79 | |
| 80 | diff --git a/src/google/protobuf/generated_message_tctable_lite.cc b/src/google/protobuf/generated_message_tctable_lite.cc |
| 81 | index 9993811dca3229edc766061c4a8d54933bcb0eba..2268b2be4d4c60c545765469549d73c6a468dac8 100644 |
| 82 | --- a/src/google/protobuf/generated_message_tctable_lite.cc |
| 83 | +++ b/src/google/protobuf/generated_message_tctable_lite.cc |
| 84 | @@ -770,7 +770,7 @@ PROTOBUF_NOINLINE const char* TcParser::SingularVarBigint( |
| 85 | }; |
| 86 | volatile Spill spill = {data.data, msg, table, hasbits}; |
| 87 | |
| 88 | - uint64_t tmp; |
| 89 | + uint64_t tmp = 0; |
| 90 | PROTOBUF_ASSUME(static_cast<int8_t>(*ptr) < 0); |
| 91 | ptr = ParseVarint(ptr, &tmp); |
| 92 | |
| 93 | @@ -845,7 +845,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedVarint( |
| 94 | auto expected_tag = UnalignedLoad<TagType>(ptr); |
| 95 | do { |
| 96 | ptr += sizeof(TagType); |
| 97 | - uint64_t tmp; |
| 98 | + uint64_t tmp = 0; |
| 99 | ptr = ParseVarint(ptr, &tmp); |
| 100 | if (ptr == nullptr) { |
| 101 | return Error(PROTOBUF_TC_PARAM_PASS); |
| 102 | @@ -1001,7 +1001,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::SingularEnum( |
| 103 | } |
| 104 | const char* ptr2 = ptr; // Save for unknown enum case |
| 105 | ptr += sizeof(TagType); // Consume tag |
| 106 | - uint64_t tmp; |
| 107 | + uint64_t tmp = 0; |
| 108 | ptr = ParseVarint(ptr, &tmp); |
| 109 | if (ptr == nullptr) { |
| 110 | return Error(PROTOBUF_TC_PARAM_PASS); |
| 111 | @@ -1052,7 +1052,7 @@ PROTOBUF_ALWAYS_INLINE const char* TcParser::RepeatedEnum( |
| 112 | do { |
| 113 | const char* ptr2 = ptr; // save for unknown enum case |
| 114 | ptr += sizeof(TagType); |
| 115 | - uint64_t tmp; |
| 116 | + uint64_t tmp = 0; |
| 117 | ptr = ParseVarint(ptr, &tmp); |
| 118 | if (ptr == nullptr) { |
| 119 | return Error(PROTOBUF_TC_PARAM_PASS); |
| 120 | @@ -1477,7 +1477,7 @@ const char* TcParser::MpVarint(PROTOBUF_TC_PARAM_DECL) { |
| 121 | |
| 122 | // Parse the value: |
| 123 | const char* ptr2 = ptr; // save for unknown enum case |
| 124 | - uint64_t tmp; |
| 125 | + uint64_t tmp = 0; |
| 126 | ptr = ParseVarint(ptr, &tmp); |
| 127 | if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); |
| 128 | |
| 129 | @@ -1542,7 +1542,7 @@ const char* TcParser::MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL) { |
| 130 | const char* ptr2 = ptr; |
| 131 | uint32_t next_tag; |
| 132 | do { |
| 133 | - uint64_t tmp; |
| 134 | + uint64_t tmp = 0; |
| 135 | ptr = ParseVarint(ptr2, &tmp); |
| 136 | if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); |
| 137 | field.Add(is_zigzag ? WireFormatLite::ZigZagDecode64(tmp) : tmp); |
| 138 | @@ -1554,7 +1554,7 @@ const char* TcParser::MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL) { |
| 139 | const char* ptr2 = ptr; |
| 140 | uint32_t next_tag; |
| 141 | do { |
| 142 | - uint64_t tmp; |
| 143 | + uint64_t tmp = 0; |
| 144 | ptr = ParseVarint(ptr2, &tmp); |
| 145 | if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); |
| 146 | if (is_validated_enum) { |
| 147 | @@ -1575,7 +1575,7 @@ const char* TcParser::MpRepeatedVarint(PROTOBUF_TC_PARAM_DECL) { |
| 148 | const char* ptr2 = ptr; |
| 149 | uint32_t next_tag; |
| 150 | do { |
| 151 | - uint64_t tmp; |
| 152 | + uint64_t tmp = 0; |
| 153 | ptr = ParseVarint(ptr2, &tmp); |
| 154 | if (ptr == nullptr) return Error(PROTOBUF_TC_PARAM_PASS); |
| 155 | field.Add(static_cast<bool>(tmp)); |
| 156 | diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc |
| 157 | index 487e1b8a379b86bfa3097d68a64ee0a727d36cab..53997901f333292f71ac52e7f9c876bd918f7bf6 100644 |
| 158 | --- a/src/google/protobuf/io/coded_stream.cc |
| 159 | +++ b/src/google/protobuf/io/coded_stream.cc |
| 160 | @@ -462,7 +462,7 @@ int64_t CodedInputStream::ReadVarint32Fallback(uint32_t first_byte_or_zero) { |
| 161 | (buffer_end_ > buffer_ && !(buffer_end_[-1] & 0x80))) { |
| 162 | GOOGLE_DCHECK_NE(first_byte_or_zero, 0) |
| 163 | << "Caller should provide us with *buffer_ when buffer is non-empty"; |
| 164 | - uint32_t temp; |
| 165 | + uint32_t temp = 0; |
| 166 | ::std::pair<bool, const uint8_t*> p = |
| 167 | ReadVarint32FromArray(first_byte_or_zero, buffer_, &temp); |
| 168 | if (!p.first) return -1; |