strdup(NULL) supposed to create SIGSEGV?

看板FB_hackers作者時間17年前 (2008/04/26 14:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串25/25 (看更多)
On Thu, Apr 24, 2008 at 1:24 AM, Bakul Shah <bakul@bitblocks.com> wrote: > On Wed, 23 Apr 2008 23:34:41 PDT "Garrett Cooper" <yanefbsd@gmail.com> > wrote: > > I know that dereferencing a NULL pointer yields a segfault because > address 0 > > can't be accessed. > > > > The point is that I didn't realize that something unadvertised causes a > > SIGSEGV. > > I understood that. We all learn this the hard way! Reading > that something will cause SIGSEGV doesn't have the same > impact as actually seeing your program crash! > > > If someone noted that strdup(2) used memcpy(2) (at least) and didn't > check > > input (at most), I would completely understand.. I'm more than happy to > > write that up in the revised manpage if that's what it takes, so others > > unaware of this can avoid this issue.. > > strdup(NULL) is an example of the more general case of using > an illegal value for a function argument. Are you going to > update all the manpages for functions that segfault when > given a NULL? I guess what I am trying to say is don't waste > your time on that -- even if you update all manpages, people > are still going to trip over this at least once. > > cc -Wall can help find such problems. For strdup(NULL) > you will get something like > > x.c:5: warning: null argument where non-null required (argument 1) > > So if you want to help others, make them use cc -Wall :-) > When using things such as getopt, which depend on user input, you can't do that. gcc is good at mapping out graphs, but it's no more proficient of a guesser than I am. Besides, it doesn't have a fake Jamaican accent :].. I agree though to some extent about the manpage thing, even though this stupid mistake bit me in the ass due to my own ignorance. Also, strdup(3) should reference memcpy(3) in the manpage. I'll submit a patch for that. Discussion closed. -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): #184irE00 (FB_hackers)
討論串 (同標題文章)
文章代碼(AID): #184irE00 (FB_hackers)