Tzafrir Cohen wrote:

There is one popular strncpy alternative that doesn't seem to do this
padding: strlcpy

http://www.courtesan.com/todd/papers/strlcpy.html

That paper covers exactly the issue we are discussing here, thanks for the reference.


strlcpy has one feature that we don't use in Asterisk; it still has a return value, and it returns the length of the string it wanted to create, so you can determine whether truncation occurred or not. Since very few places in Asterisk bother to even check the return value, this too is wasted CPU cycles.

At this point, it's pretty clear to me that the semantics of ast_copy_string() are exactly what we want, and the only remaining issue is whether there should be optimized versions produced. I'm going to start the conversion process from strncpy() to ast_copy_string() in CVS HEAD, and we'll see where things lead from there.
_______________________________________________
Asterisk-Dev mailing list
[email protected]
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to