> Jon Steinhart <[EMAIL PROTECTED]> writes:
> 
> > 3.  If the $HOME environment variable is set, mypath is copied from the
> >     getenv return.  Why?  It's never changed.
> > 
> > 4.  If the $HOME environment variable is not set, mypath is copied from the
> >     pw_dir member of the returned passwd structure.  Now, I understand that
> >     this is a static structure, but getpwuid is never called again so I
> >     don't see why the copy is needed.
> > 
> > 4.  If the $HOME environment variable is not set, the pw_dir member of the
> >     passwd structure returned by getpwuid() is checked for a NULL pointer.
> >     This can never happen in a non-error return, which is already checked.
> >     So why the superfluous check?
> 
> These checks are not superflous, they are for maintainability.
> Two years from now someone will add a second getenv(3) call and
> waste their (probably volunteer) time trying to figure out how
> they busted the home dir variable.  That is why, unless you are
> writing super-tight-must-be-the-best-performing-code-ever
> applications (which mh is not), it is necessary always to make a
> copy of the static buffer pointed to by the return values of such
> functions.
> 
> --  
> Eric Gillespie <*> [EMAIL PROTECTED]

This is one of those places where we'll have to respectfully disagree.  I'm
obviously in the minority given the quality of software that I see these days,
but I think that programming is still something that should be done by
professionals.  I don't want someone hacking on code that doesn't take the time
to figure out what's going on first.  Protecting against the really silly
mistakes allows such people to make really complex ones.  As I said in my
earlier email, I'm not going to write slow and sloppy  code just because
computers are fast.  Matter of fact, I keep on trying to get up the courage
to tackle m_getfld().

Oh, some details.

 1.  A second getenv() call would not break the code.  The copy was really
     unnecessary.

 2.  It's hard for me to imagine a situation where getpwuid() would #1 get
     called a second time and #2 for a different uid, which is the only that
     a problem would occur.

 3.  If there's a NULL passwd->pw_dir then libc is broken and should be fixed.
     Better that this gets pointed out and fixed rather than covered up so that
     it stays unnoticed and broken.

Oh, and I've wasted some of my volunteer time trying to figure out what the
code did before changing it.  I'd waste less if there was less code.  Best way
to accomplish this is to get rid of the code that doesn't do anything.

Jon

Reply via email to