From owner-freebsd-hackers Sat Jan 11 18:19:02 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id SAA24806 for hackers-outgoing; Sat, 11 Jan 1997 18:19:02 -0800 (PST) Received: from genesis.atrad.adelaide.edu.au (genesis.atrad.adelaide.edu.au [129.127.96.120]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id SAA24801 for ; Sat, 11 Jan 1997 18:18:58 -0800 (PST) Received: (from msmith@localhost) by genesis.atrad.adelaide.edu.au (8.8.2/8.7.3) id MAA09886; Sun, 12 Jan 1997 12:47:50 +1030 (CST) From: Michael Smith Message-Id: <199701120217.MAA09886@genesis.atrad.adelaide.edu.au> Subject: Re: unused variable in su In-Reply-To: <199701111939.MAA24005@phaeton.artisoft.com> from Terry Lambert at "Jan 11, 97 12:39:07 pm" To: terry@lambert.org (Terry Lambert) Date: Sun, 12 Jan 1997 12:47:49 +1030 (CST) Cc: joerg_wunsch@uriah.heep.sax.de, hackers@freebsd.org X-Mailer: ELM [version 2.4ME+ PL28 (25)] 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. > Terry Lambert -- ]] Mike Smith, Software Engineer msmith@gsoft.com.au [[ ]] Genesis Software genesis@gsoft.com.au [[ ]] High-speed data acquisition and (GSM mobile) 0411-222-496 [[ ]] realtime instrument control. (ph) +61-8-8267-3493 [[ ]] Unix hardware collector. "Where are your PEZ?" The Tick [[