On Tue, Jan 27, 2026 at 03:20:53PM +0100, Alejandro Colomar wrote:
I think calling this 'pathlen' can be misleading.  It is the size of the
buffer (sizeof), not the length of the string (strlen).  Confusing
length with size can often lead to off-by-one bugs.  I would call it
pathsize (or just size).

And then, I'd avoid the explicit +1, as it can also cause off-by-one
bugs.  A common idiom would be:

        if (len >= size)

+      len = pathlen - 1;

Thank you Alejandro!

I completely agree with both of these comments.

However, in this case, I was following the existing code, and refactoring/reusing it rather than trying to improve it. :D

I'll add to my list to fix in a separate patch.

Is truncation okay?  I guess in this place it's not too bad, as the
'From ' line is relatively unimportant, but just to confirm.

Yeah, in this case I think it's okay. It's passing a buffer of 256, and the value isn't that important.

--
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C  5308 ADEF 7684 8031 6BDA

Attachment: signature.asc
Description: PGP signature

Reply via email to