strdup(NULL) supposed to create SIGSEGV?

Hans Petter Selasky hselasky at c2i.net
Wed Apr 23 18:56:34 UTC 2008


Hi,

I recently had to tell someone that "strncpy" does not always zero terminate 
the destination string. Surprised by what I was telling they immediately 
wanted to change the way the function worked. When a function is defined by 
an ISO standard you are not supposed to change the definition. Instead I 
pointed the person at "strlcpy". Else you will have serious trouble when code 
is ported to a new platform.

http://www.gratisoft.us/todd/papers/strlcpy.html

The name "strdup" is very appealing, but it has already been taken and 
defined. You have to give your variant a different name and convince everyone 
that your function is good and solves a problem so that it deserves to be in 
the C-library.

Then you simply run a script on your code:

sed -s "s/ strdup[(]/ strsdup(/g" *.[ch]

--HPS

:-)


More information about the freebsd-hackers mailing list