Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!uw-beaver!tektronix!reed!psu-cs!omepd!perry From: perry@inteloa.intel.com (Perry The Cynic) Newsgroups: comp.sys.ibm.pc Subject: Re: MSC 4.0 and the Twilight Zone Message-ID: <635@omepd> Date: Mon, 4-May-87 18:33:50 EDT Article-I.D.: omepd.635 Posted: Mon May 4 18:33:50 1987 Date-Received: Wed, 6-May-87 01:06:47 EDT References: <2454@uw-june.UUCP> Sender: news@omepd Reply-To: perry@inteloa.intel.com (Perry The Cynic) Distribution: na Organization: Intel Corp., Hillsboro Lines: 15 Summary: *strdup*-allocated strings canNOT be extended In article <2454@uw-june.UUCP> roper@uw-june.UUCP (Michael Roper) writes: >Can anyone please explain the behavior of the following few lines of code? > [...showing a sample program containing the following lines of code:] > s = strdup (argv[1]); > strcat (s, ".U"); *strdup* allocates exactly enough memory to hold a copy of its argument plus the zero byte terminator. Your *strcat* tries to write *beyond* this area, effectively corrupting the heap area. The next allocation (strdup) that you (dynamically) make clobbers the byte holding the "U" (the "." replaces the zero byte and is `safe' :-). -- perry ------------------------------------------------------------------------ << Perry The Cynic >> =>> perry@inteloa.intel.com <<= ...!tektronix!ogcvax!omepd!inteloa!perry (Peter Kiehtreiber) ...!verdix!omepd!inteloa!perry