malloc() problem on sysv386

Larry Campbell campbell at redsox.bsw.com
Sun May 26 06:12:30 AEST 1991


In article <4161 at uc.msc.umn.edu> jeff at 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 at redsox.bsw.com    Boston, Massachusetts 02109 (USA)



More information about the Comp.unix.sysv386 mailing list