Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!think.com!redsox!campbell From: campbell@redsox.bsw.com (Larry Campbell) Newsgroups: comp.unix.sysv386 Subject: Re: malloc() problem on sysv386 Message-ID: <1991May25.201230.26190@redsox.bsw.com> Date: 25 May 91 20:12:30 GMT References: <1991May23.094026.18969@hollie.rdg.dec.com> <1991May24.024307.29104@swsrv1.cirr.com> <4161@uc.msc.umn.edu> Reply-To: campbell@redsox.bsw.com (Larry Campbell) Organization: The Boston Software Works, Inc. Lines: 19 In article <4161@uc.msc.umn.edu> jeff@uf.UUCP (Jeff Turner) writes: - -Wrong: - cp = "string"; - new_cp = malloc(strlen(cp)); - strcpy(new_cp, cp); - -Right: - cp = "string"; - new_cp = malloc(strlen(cp)+1); - strcpy(new_cp, cp); Better: cp = "string"; new_cp = strdup(cp); -- Larry Campbell The Boston Software Works, Inc., 120 Fulton Street campbell@redsox.bsw.com Boston, Massachusetts 02109 (USA)