strdup(NULL) supposed to create SIGSEGV?

看板FB_hackers作者時間17年前 (2008/04/23 13:41), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/25 (看更多)
Hi all, I made an oops in a program, which uncovered "feature" in strdup(2) that I wasn't aware of before. So I was wondering, is strdup(pointer = NULL) supposed to segfault should this just return NULL and set errno? Good news is that Linux does the same thing (yay?), so at least FreeBSD isn't alone.. Sample: [gcooper@optimus ~]$ ss="strdup_segfault"; gcc -o $ss $ss.c; ./$ss; cat $ss.c Segmentation fault: 11 (core dumped) #include <string.h> int main() { const char *null_src_p = NULL; char *null_dest_p = strdup(null_src_p); return 0; } My sources are a bit old (last sync and userland recompile was mid~March) but I don't think that libc changes all that often. [gcooper@optimus ~]$ uname -a FreeBSD optimus 8.0-CURRENT FreeBSD 8.0-CURRENT #10: Wed Apr 16 19:47:39 PDT 200 8 root@optimus:/usr/obj/usr/src/sys/OPTIMUS i386 Thanks, -Garrett _______________________________________________ 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): #183im300 (FB_hackers)
討論串 (同標題文章)
文章代碼(AID): #183im300 (FB_hackers)