[lxc-devel] [PATCH 2/2] c/r: use sizeof instead of magic numbers

Serge Hallyn serge.hallyn at ubuntu.com
Thu Oct 16 20:45:04 UTC 2014


Quoting Tycho Andersen (tycho.andersen at canonical.com):
> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  src/lxc/lxccontainer.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 61d06ea..b9eab17 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -3591,16 +3591,16 @@ static void exec_criu(struct criu_opts *opts)
>  			struct lxc_netdev *n = it->elem;
>  
>  			if (n->name) {
> -				if (strlen(n->name) >= 128)
> +				if (strlen(n->name) >= sizeof(eth))
>  					goto err;
> -				strncpy(eth, n->name, 128);
> +				strncpy(eth, n->name, sizeof(eth));
>  			} else
>  				sprintf(eth, "eth%d", netnr);
>  
>  			veth = n->priv.veth_attr.pair;
>  
> -			ret = snprintf(buf, 257, "%s=%s", eth, veth);
> -			if (ret < 0 || ret >= 257)
> +			ret = snprintf(buf, sizeof(buf), "%s=%s", eth, veth);
> +			if (ret < 0 || ret >= sizeof(buf))
>  				goto err;
>  
>  			/* final NULL and --veth-pair eth0=vethASDF */
> -- 
> 1.9.1
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list