On Wed, Sep 30, 2026 at 09:30:01AM +0200, Alejandro Colomar via Mutt-dev wrote:
diff --git a/buffer.c b/buffer.c index 24815b95..75ac28fb 100644 --- a/buffer.c +++ b/buffer.c @@ -191,7 +191,8 @@ void mutt_buffer_addstr_n(BUFFER *buf, const char *s, size_t len) if (!buf->data || (buf->dptr + len + 1 > buf->data + buf->dsize)) mutt_buffer_increase_size(buf, buf->dsize + (len < 128 ? 128 : len + 1)); - memcpy(buf->dptr, s, len); + if (s && len)You don't need to test whether 'len' is nonzero. memcpy(,,0) is defined to be a no-op. BTW, out of curiosity, can 's' be NULL here in some path? It would be interesting to note in the commit message which conditions could make it happen. Or is it just out of caution?
I noticed some of the ACCOUNT fields were being used in buffer add operations, so I added this commit out of caution. In those cases, len would be 0. If you're sure that's safe then this is an optional patch that I can drop.
BTW, memcpy(NULL,NULL,0) is also defined to be valid and a no-op, as accorded by the C Committee for ISO C2y (to become C29, most likely), and in practice, it already works in every compiler because C++ requires it. NULL pointers are invalid only if len!=0.
Thank you! -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA
signature.asc
Description: PGP signature
