Re: strdup(NULL) supposed to create SIGSEGV?

看板FB_hackers作者時間17年前 (2008/04/23 19:58), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串12/25 (看更多)
On 2008-04-23, Simun Mikecin wrote: > According to Open Group strdup should return NULL and set errno. Look at: > http://www.opengroup.org/onlinepubs/009695399/functions/strdup.html If you're going to quote documents to support your ideas, it's probably better to read them first. That document gives only lack of memory as a reason for failure. It does not state clearly, but clearly requires, correct behaviour from the caller who is required to provide a string argument. NULL is not a string, so the behaviour of the function is undefined. Basic C programming requires people not to step into the wilderness of undefined behaviour. > There is no valid argument for doing segfault instead of above behavior. If you can find an alternative that is not actually wrong, then by all means share it. To me, it seems like a good choice. Clearly, I am not alone. Greg _______________________________________________ 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): #183oHw00 (FB_hackers)
討論串 (同標題文章)
文章代碼(AID): #183oHw00 (FB_hackers)