Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 12 Jan 1997 11:54:41 -0700 (MST)
From:      Terry Lambert <terry@lambert.org>
To:        msmith@atrad.adelaide.edu.au (Michael Smith)
Cc:        terry@lambert.org, joerg_wunsch@uriah.heep.sax.de, hackers@FreeBSD.ORG
Subject:   Re: unused variable in su
Message-ID:  <199701121854.LAA25878@phaeton.artisoft.com>
In-Reply-To: <199701120217.MAA09886@genesis.atrad.adelaide.edu.au> from "Michael Smith" at Jan 12, 97 12:47:49 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> 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.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199701121854.LAA25878>