Re: [PATCH 01/19] last: stop using MAXHOSTNAMELEN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sunday 14 October 2012 16:20:52 Sami Kerola wrote:
> --- a/login-utils/last.c
> +++ b/login-utils/last.c
> @@ -418,22 +418,19 @@ addtty(char *ttyname) {
>   */
>  static void
>  hostconv(char *arg) {
> -	static int	first = 1;
> -	static char	*hostdot,
> -			name[MAXHOSTNAMELEN];
> -	char	*argdot;
> +	static char *hostdot;
> +	static char *argdot;
> +	static char *name;
> 
>  	if (!(argdot = strchr(arg, '.')))
>  		return;
> -	if (first) {
> -		first = 0;
> -		if (gethostname(name, sizeof(name)))
> -			err(EXIT_FAILURE, _("gethostname failed"));
> -
> -		hostdot = strchr(name, '.');
> -	}
> +	name = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
> +	if (gethostname(name, sysconf(_SC_HOST_NAME_MAX)))
> +		err(EXIT_FAILURE, _("gethostname failed"));
> +	hostdot = strchr(name, '.');
>  	if (hostdot && !strcmp(hostdot, argdot))
>  		*argdot = '\0';
> +	free(name);
>  }

marking argdot static doesn't make sense

the way you're rewritten things also doesn't make sense to have "name" be 
static.  i'd go so far as to say it's wrong.  keep the existing "first" logic.
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux