Xref: utzoo comp.sources.wanted:15306 alt.sources.wanted:933 Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool.mu.edu!think.com!mintaka!mintaka.lcs.mit.edu!rearl From: rearl@spiff.ai.mit.edu (Robert Earl) Newsgroups: comp.sources.wanted,alt.sources.wanted Subject: Re: What is strdup() supposed to do? Does anyone have a copy? Message-ID: Date: 17 Feb 91 10:11:33 GMT References: <1991Feb14.050716.9501@shibaya.lonestar.org> <1991Feb17.045913.17126@sbcs.sunysb.edu> Sender: daemon@mintaka.lcs.mit.edu (Lucifer Maleficius) Organization: EVIL! Lines: 25 In-Reply-To: cbrown@eeserv1.ic.sunysb.edu's message of 17 Feb 91 04:59:13 GMT In article <1991Feb17.045913.17126@sbcs.sunysb.edu> cbrown@eeserv1.ic.sunysb.edu (Charles T Brown) writes: | In article <1991Feb14.050716.9501@shibaya.lonestar.org> afc@shibaya.lonestar.org (Augustine Cano) writes: | >While attempting to compile the recently posted procmail package, I could | >not fine strdup() in any library, on any of the machines I have access to. | | char * strdup (s) | | char * s; | { | char * rets; | | rets=malloc (sizeof (char) * strlen (s)); This is wrong; you haven't allocated enough space for the whole string, which is terminated by a final ASCII NUL ('\0'). It should be "strlen (s) + 1". It'd also be nice to cast the return value of malloc to (char *) and check for NULL, especially on architectures that won't necessarily catch writes to a zero pointer. -- robert earl rearl@geech.ai.mit.edu