From owner-freebsd-bugs Fri Mar 14 01:34:25 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id BAA09897 for bugs-outgoing; Fri, 14 Mar 1997 01:34:25 -0800 (PST) Received: from lilac.csi.cam.ac.uk (exim@lilac.csi.cam.ac.uk [131.111.8.44]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id BAA09891 for ; Fri, 14 Mar 1997 01:34:19 -0800 (PST) Received: from g.pet.cam.ac.uk [131.111.209.233] by lilac.csi.cam.ac.uk with smtp (Exim 1.58 #1) id 0w5TNP-0007Ru-00; Fri, 14 Mar 1997 09:34:15 +0000 Received: from g.pet.cam.ac.uk [127.0.0.1] by g.pet.cam.ac.uk with esmtp (Exim 1.59 #1) id 0w5TNh-0006W2-00; Fri, 14 Mar 1997 09:34:33 +0000 To: freebsd-bugs@freebsd.org Subject: Re: bin/2969: csh and/or builtin printf has problems with embedded commands In-reply-to: Your message of "Thu, 13 Mar 1997 01:19:29 +0100." <199703130019.BAA04142@ghost.mep.ruhr-uni-bochum.de> Date: Fri, 14 Mar 1997 09:34:33 +0000 From: Gareth McCaughan Message-Id: Sender: owner-bugs@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Robert Eckard wrote: > printf with a shell command as its argument > prints wrong results. Happens only for builtin printf > in /usr/bin/csh. What's actually happening is that the csh built-in printf isn't expanding its arguments. The "printf" builtin isn't actually documented in the manpage (!), but this sounds like a bug since it presumably is meant to behave like /usr/bin/printf. I believe that the following patch fixes the problem. ---------- patch begins ---------- *** func.c.orig Thu Mar 13 19:04:20 1997 --- func.c Fri Mar 14 09:27:40 1997 *************** *** 1489,1497 **** --- 1489,1510 ---- Char **v; struct command *t; { + Char **newv; char **c; extern int progprintf __P((int, char **)); int ret; + + gflag = 0; + tglob(v); + if (gflag) { + newv = globall(v); + if (newv == 0) { + stderror(ERR_NAME | ERR_NOMATCH); + return; + } + v = newv; + gargv=0; + } ret = progprintf(blklen(v), c = short2blk(v)); (void) fflush(cshout); ----------- patch ends ----------- Incidentally, there is a memory leak somewhere around here in csh. (The arguments to "doprintf" aren't getting freed.) I'm not suggesting a fix because I really don't want to have to read the code carefully enough to be sure I wouldn't introduce a bug that freed things twice. >From a cursory look at the code I suspect that there are in fact about 100000 memory leaks of this kind. Yeeuch. -- Gareth McCaughan Dept. of Pure Mathematics & Mathematical Statistics, gjm11@dpmms.cam.ac.uk Cambridge University, England.