AIX usrinfo() cleanup.

Gert Doering gert at greenie.muc.de
Fri Jul 5 07:58:01 EST 2002


Hi,

On Thu, Jul 04, 2002 at 12:51:48PM -0500, Ben Lindstrom wrote:
> > > > -	cp = xmalloc(22 + strlen(tty) + 2 * strlen(pw->pw_name));
> > > > -	i = sprintf(cp, "LOGNAME=%s%cNAME=%s%cTTY=%s%c%c", pw->pw_name, 0,
> > > > -	    pw->pw_name, 0, tty, 0, 0);
> > > > +	cp = xmalloc(16 + 2 * strlen(pw->pw_name));
> > > > +	i = sprintf(cp, "LOGNAME=%s%cNAME=%s%c%c", pw->pw_name, 0,
> > > > +	    pw->pw_name, 0, 0);
> > >
> > > Doesn't sprintf add a trailing NULL to the end?  Don't you need to
> > > xmalloc(16+2*strlen(pw->pw_name)+1)?
> >
> > Indeed.  The new string is 5 (plus strlen(tty)) characters shorter, not 6.
> 
> The other question that I was going to ask was why are we putting 3 \0 at
> the end of the string?

Well... my original version had the two %c%c ... ,0,0 there to make it
really explicit that it's "two 0-bytes here to terminate the list of
items".

Of course the implicit 0-byte added by sprintf will do.

gert
-- 
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             gert at greenie.muc.de
fax: +49-89-35655025                        gert.doering at physik.tu-muenchen.de



More information about the openssh-unix-dev mailing list