Hi Kevin,

> Date: 2026-09-30 12:45:43+0800
> From: "Kevin J. McCarthy" <[email protected]>
>
> ---
>  buffer.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> 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?

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.


Have a lovely day!
Alex

> +    memcpy(buf->dptr, s, len);
>    buf->dptr += len;
>    *(buf->dptr) = '\0';
>  }
> -- 
> 2.55.0
> 

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to