From owner-freebsd-hackers Sun Jan 12 11:06:53 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id LAA11404 for hackers-outgoing; Sun, 12 Jan 1997 11:06:53 -0800 (PST) Received: from phaeton.artisoft.com (phaeton.Artisoft.COM [198.17.250.211]) by freefall.freebsd.org (8.8.4/8.8.4) with SMTP id LAA11397 for ; Sun, 12 Jan 1997 11:06:50 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id LAA25878; Sun, 12 Jan 1997 11:54:41 -0700 From: Terry Lambert Message-Id: <199701121854.LAA25878@phaeton.artisoft.com> Subject: Re: unused variable in su To: msmith@atrad.adelaide.edu.au (Michael Smith) Date: Sun, 12 Jan 1997 11:54:41 -0700 (MST) Cc: terry@lambert.org, joerg_wunsch@uriah.heep.sax.de, hackers@FreeBSD.ORG In-Reply-To: <199701120217.MAA09886@genesis.atrad.adelaide.edu.au> from "Michael Smith" at Jan 12, 97 12:47:49 pm X-Mailer: ELM [version 2.4 PL24] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk > Terry Lambert stands accused of saying: > > > > Personally, I'd use strdup() istead of an auto buffer to allocate > > the buffer at whatever size is necessary... ie: get rid of shellbuf > > entirely and replace: > > > > shell = strcpy(shellbuf, pwd->pw_shell); > > with: > > shell = strdup( pwd->pw_shell); > > > > But, hey, that's me, using strdup() for what it was intended to do. > > You could, however, try reading the code in question, and note that > shell is potentially reassigned several times. You would either have > to record whether it was pointing at a strdup'd string as opposed to > the statically-assigned cpp constant, or you could unconditionally > strdup every time and always free it before reassigning. Personally, > I think that the original code is the most readable alternative. Well, I claimed that before the code was mangled to "(void)strcpy( ...)"; if the intent was to get rid of the static buffer, though, strdup is as good a method as any other. Clearly, the process isn't long-lived enough to care about reallocating data space without freeing it... the _exit() will clear the process address space in any event (execve/exit). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.