Initialize encoding/decoding buffers with null pointers

closes #1

> the caller has no way to know if they need to free it or not

while this is not necessarily true--the buffer is only allocated on succesful return codes--it is indeed better practice to ensure the pointers are nullified. This prevents future accidental mal-use leading to corruption when freeing an uninitialized pointer.
This commit is contained in:
Jop Zitman 2025-06-05 09:42:46 +08:00
parent 3ada0c8059
commit c2386d344a
3 changed files with 7 additions and 3 deletions

View file

@ -91,6 +91,8 @@ ssize_t client_encode_segment(dns_packet_t* packet, size_t* packet_len, const un
}
ssize_t client_encode(void* slot_p, void* callback_ctx, unsigned char** dest_buf, const unsigned char* src_buf, size_t src_buf_len, size_t* segment_len, struct sockaddr_storage* peer_addr, struct sockaddr_storage* local_addr) {
*dest_buf = NULL;
// optimize path for single segment
if (src_buf_len <= *segment_len) {
#ifdef NOENCODE