Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!brl-adm!seismo!mcvax!ace!konijn From: konijn@ace.UUCP Newsgroups: comp.bugs.4bsd Subject: repl(1) dumps core + fix Message-ID: <248@ace.UUCP> Date: Tue, 24-Mar-87 13:14:17 EST Article-I.D.: ace.248 Posted: Tue Mar 24 13:14:17 1987 Date-Received: Fri, 27-Mar-87 04:33:01 EST Sender: henk@ace.UUCP Reply-To: konijn@ace.UUCP (Erik van Konijnenburg) Distribution: world Organization: ACE Associated Computer Experts bv, Amsterdam Lines: 43 Index: /usr/src/new/mh/uip/replsbr.c Description: The repl(1) command, part of MH-6.4, dumps core on mc68000 machines. The command allocates an array of pointers, with each pointer pointing to an allocated buffer. The buffers are freed by a loop that stops on the first NULL pointer. This happens to work OK on a VAX, presumably because calloc() returns a larger piece of memory than was requested. On my machine it doesn't. Repeat-By: Use repl(1) on an mc68000 machine. Fix: A quick hack: calloc() an extra field in the array of pointers. This field is initialised to NULL and will end the loop that frees all allocated buffers. *** replsbr.c Fri Mar 20 15:51:00 1987 --- /tmp/1 Fri Mar 20 19:44:03 1987 *************** *** 71,78 **** cp = new_fs (form ? form : replcomps, NULLCP, NULLCP); format_len = strlen (cp); ncomps = fmt_compile (cp, &fmt) + 1; ! /* allocate one extra pointer, null to stop freeing loop */ ! nxtbuf = compbuffers = (char **)calloc((unsigned)(ncomps+1),sizeof(char *)); if (nxtbuf == NULL) adios (NULLCP, "unable to allocate component buffers"); used_buf = (struct comp **)calloc((unsigned)(ncomps+1),sizeof(struct comp *)); --- 71,77 ---- cp = new_fs (form ? form : replcomps, NULLCP, NULLCP); format_len = strlen (cp); ncomps = fmt_compile (cp, &fmt) + 1; ! nxtbuf = compbuffers = (char **)calloc((unsigned)ncomps,sizeof(char *)); if (nxtbuf == NULL) adios (NULLCP, "unable to allocate component buffers"); used_buf = (struct comp **)calloc((unsigned)(ncomps+1),sizeof(struct comp *)); --------- Erik van Konijnenburg, , ...!mcvax!ace!konijn, ACE Associated Computer Experts bv, Amsterdam, the Netherlands