Subject: RE: [hackers-il] origins of strncpy

From: Chen Shapira <[email-masked]>
Date: Tue, 11 Jan 2005 10:19:10 +0200

> In case you wonder - I preffer inconditional zeroing
> of the last character in the buffer after a call to
> strncpy. If there was a zero already, I just had payed
> for accessing a memory - without a reason. Cost of
> this operation? Maybe a cache line was flushed, but
> maybe it was not - low enough compared to a branch.

[Chen Shapira] I prefer the "if" version, because it is self documenting.
When another programmer reads the code, he sees exactly the issue you had in
mind (maybe the string was too long) and the fix (write the \0).
If you just have a line writing \0 after every strncpy, there will be
someone who won't understand why the line is there, he'll delete it, test
few simple cases, see that everything works fine without this line and
decide that it really wasn't necessary.

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________