Re: strdup(NULL) supposed to create SIGSEGV?

看板FB_hackers作者時間17年前 (2008/04/24 06:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串24/25 (看更多)
On Wed, 23 Apr 2008 19:57:47 +0200, Hans Petter Selasky <hselasky@c2i.net> = wrote: > 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. Right on the spot, Hans :) You may have to pick a name that doesn't start from "str", though, because the "str*" function names are reserved for future extensions to the standard. ISO/IEC 9899:1999 (E), page 401, =C2=A77.26.11 says: 7.26 Future library directions [...] 7.26.11 String handling <string.h> 1 Function names that begin with "str", "mem", or "wcs" and a lowercase letter may be added to the declarations in the <string.h> header. You're quite right about 'not replacing' the standard functions in a lighthearted manner though. The short-term benefits of making a single application "easier to write", are dwarfed by the possibilities for introducing gratuitous incompatibilities for all the _other_ programs running on the same platform, and any other platforms conforming to the "real" standard behavior. _______________________________________________ freebsd-hackers@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-hackers To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
文章代碼(AID): #183xQV00 (FB_hackers)
討論串 (同標題文章)
文章代碼(AID): #183xQV00 (FB_hackers)