[CRIU] [crtools-bot] A few cleanups to uts_ns

Kir Kolyshkin kir at parallels.com
Tue Jan 31 15:01:57 EST 2012


On 01/31/2012 11:35 PM, Cyrill Gorcunov wrote:
> The commit is pushed to "master" and will appear on git://github.com/cyrillos/crtools.git
> ------>
> commit ca099959343463088387df332107c2a6c5d47186
> Author: Cyrill Gorcunov<gorcunov at openvz.org>
> Date:   Tue Jan 31 23:29:24 2012 +0400
>
>      A few cleanups to uts_ns
>
>       - drop hardcoded numbers, use sizeof
>       - drop unneeded local argument
>
>      Signed-off-by: Cyrill Gorcunov<gorcunov at openvz.org>
> ---
>   uts_ns.c |    7 +++----
>   1 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/uts_ns.c b/uts_ns.c
> index af16805..04bfced 100644
> --- a/uts_ns.c
> +++ b/uts_ns.c
> @@ -14,7 +14,7 @@ static int dump_uts_string(int fd, char *str)
>
>   	len = strlen(str);
>   	ret = write_img(fd,&len);
> -	if (ret == 0)
> +	if (!ret)

This is a controversial change. Although (!ret) is kinda classic, (ret 
== 0) is a bit more readable for me than (!ret). The only problem with 
== version is sometimes it can be mistyped as =, but modern compilers do 
warn in this case. So I would left it as is (no need to change again 
though, just for the future).

>   		ret = write_img_buf(fd, str, len);
>
>   	return ret;
> @@ -52,7 +52,7 @@ static int prepare_uts_str(int fd, char *n)
>
>   	ret = read_img(fd,&len);
>   	if (ret>  0) {
> -		if (len>= 65) {
> +		if (len>= sizeof(str)) {
>   			pr_err("Corrupted %s\n", n);
>   			return -1;
>   		}
> @@ -91,7 +91,6 @@ int prepare_utsns(int pid)
>   {
>   	int fd, ret;
>   	u32 len;
> -	char str[65];
>
>   	fd = open_image_ro(CR_FD_UTSNS, pid);
>   	if (fd<  0)
> @@ -113,7 +112,7 @@ static void show_uts_string(int fd, char *n)
>
>   	ret = read_img(fd,&len);
>   	if (ret>  0) {
> -		if (len>= 65) {
> +		if (len>= sizeof(str)) {
>   			pr_err("Corrupted hostname\n");
>   			return;
>   		}
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://openvz.org/mailman/listinfo/criu



More information about the CRIU mailing list