[neomutt-devel] strfcpy() improvement

Darshit Shah darnir at gmail.com
Tue Oct 4 15:17:49 CEST 2016


In fact, I would suggest turning it into a function> Most modern 
compilers are smart enough to inline such a trivial function [1]. The 
more macros we get rid of, the cleaner and safer the code is.

[1]: https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Inline.html
* Fabian Groffen <grobian at gentoo.org> [161004 15:07]:
>On 04-10-2016 13:23:09 +0100, Richard Russon wrote:
>> Next, Mutt created a macro strfcpy() based on the BSD function.  It
>> guarantees a length limit AND a NULL termination.
>>
>>     #define strfcpy(DST,SRC,LEN) strncpy(DST,SRC,LEN), *(DST+(LEN)-1)=0
>>
>> Because of the way it works, it triggers a warning in Coverity (a static
>> analysis tool).  It fills DST (without NULL), then writes the NULL.
>>
>> Why have I told you all of this?  Because I'm changing the macro.
>>     dotlock.c lib.h rfc822.c
>> My testing shows it works correctly, but I may missed something.
>>
>>     #define strfcpy(DST,SRC,LEN) do { if ((LEN) > 0) { *(DST+(LEN)-1)=0; strncpy(DST,SRC,(LEN)-1); } } while (0)
>
>Why not:
>
>#define strfcpy(DST,SRC,LEN) snprintf(DST,LEN,"%s",SRC)
>
>It simplifies the macro considerably, not sure about the performance
>effect though.
>
>Fabian
>
>-- 
>Fabian Groffen
>Gentoo on a different level



-- 
Thanking You,
Darshit Shah
PGP Fingerprint: 7845 120B 07CB D8D6 ECE5 FF2B 2A17 43ED A91A 35B6
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 866 bytes
Desc: not available
URL: <http://mailman.neomutt.org/mailman/private/neomutt-devel-neomutt.org/attachments/20161004/e79b7fea/attachment.sig>


More information about the neomutt-devel mailing list