From owner-freebsd-hackers Sat Jan 11 11:50:40 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id LAA01607 for hackers-outgoing; Sat, 11 Jan 1997 11:50:40 -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 LAA01602 for ; Sat, 11 Jan 1997 11:50:35 -0800 (PST) Received: (from terry@localhost) by phaeton.artisoft.com (8.6.11/8.6.9) id MAA24005; Sat, 11 Jan 1997 12:39:07 -0700 From: Terry Lambert Message-Id: <199701111939.MAA24005@phaeton.artisoft.com> Subject: Re: unused variable in su To: joerg_wunsch@uriah.heep.sax.de Date: Sat, 11 Jan 1997 12:39:07 -0700 (MST) Cc: hackers@freebsd.org In-Reply-To: from "J Wunsch" at Jan 11, 97 01:14:24 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 > Still, it's fairly obfuscated code. It could be better worded: > > if (asme) > if (pwd->pw_shell && *pwd->pw_shell) { > (void)strcpy(shellbuf, pwd->pw_shell); > shell = shellbuf; > } else { > shell = _PATH_BSHELL; > iscsh = NO; > } > > This would be less confusing for compilers and human readers. Human readers are expected to have familiarity with the return values of standard library routines. Explicitly void casting strcpy indicates it has a return value which is being ignored, for no good reason. > Btw., shouldn't it better be a strncpy() anyway? Sure, /etc/shells is > at the mercy of the sysadmin, but he isn't unfailable. 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. 8-). Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers.