Skip to content

Commit 3b98e7a

Browse files
Dendi Suhubdyclaude
andcommitted
Fix GCC 14 -Werror=free-nonheap-object false positive in encode()
Use memcpy instead of vector::insert for sealed_payload to avoid GCC false positive on vector deallocation with inlined temporaries. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 00eef49 commit 3b98e7a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/transport/obfs4.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -684,18 +684,17 @@ std::vector<uint8_t> Obfs4Framing::encode(std::span<const uint8_t> payload) {
684684
uint16_t mask = send_drbg_.next_length_mask();
685685
uint16_t obfuscated = len ^ mask;
686686

687-
std::vector<uint8_t> output;
688-
output.reserve(2 + payload.size() + crypto::Secretbox::OVERHEAD);
689-
690-
// 1. Obfuscated length (2 bytes, big-endian)
691-
output.push_back(static_cast<uint8_t>(obfuscated >> 8));
692-
output.push_back(static_cast<uint8_t>(obfuscated & 0xff));
693-
694-
// 2. Secretbox-sealed payload
687+
// 1. Seal the payload first
695688
auto sealed_payload = crypto::Secretbox::seal(send_key_, send_nonce_, payload);
696689
increment_nonce(send_nonce_);
697690

698-
output.insert(output.end(), sealed_payload.begin(), sealed_payload.end());
691+
// 2. Build output: obfuscated_length[2] || sealed_payload
692+
// Use memcpy to avoid GCC -Werror=free-nonheap-object false positive
693+
size_t total = 2 + sealed_payload.size();
694+
std::vector<uint8_t> output(total);
695+
output[0] = static_cast<uint8_t>(obfuscated >> 8);
696+
output[1] = static_cast<uint8_t>(obfuscated & 0xff);
697+
std::memcpy(output.data() + 2, sealed_payload.data(), sealed_payload.size());
699698

700699
return output;
701700
}

0 commit comments

Comments
 (0)