Re: [PATCH v3 25/34] Adapt to VIR_STRDUP and VIR_STRNDUP in src/util/*

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

 



On 05/03/2013 04:53 PM, Michal Privoznik wrote:
>  32 files changed, 356 insertions(+), 567 deletions(-)

These functions returned 0 on success before and will need to be adjusted
since VIR_STRDUP returns 1 on a successful copy now.

> diff --git a/src/util/viridentity.c b/src/util/viridentity.c
> index c9efd3f..e2dc048 100644
> --- a/src/util/viridentity.c
> +++ b/src/util/viridentity.c

> @@ -246,12 +246,7 @@ int virIdentitySetAttr(virIdentityPtr ident,
>          goto cleanup;
>      }
>  
> -    if (!(ident->attrs[attr] = strdup(value))) {
> -        virReportOOMError();
> -        goto cleanup;
> -    }
> -
> -    ret = 0;
> +    ret = VIR_STRDUP(ident->attrs[attr], value);
>  
>  cleanup:
>      return ret;



> diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
> index 75599db..08a5599 100644
> --- a/src/util/virnetdevtap.c
> +++ b/src/util/virnetdevtap.c
> @@ -64,12 +64,7 @@ virNetDevTapGetName(int tapfd ATTRIBUTE_UNUSED, char **ifname ATTRIBUTE_UNUSED)
>          return -1;
>      }
>  
> -    *ifname = strdup(ifr.ifr_name);
> -    if (*ifname == NULL) {
> -        virReportOOMError();
> -        return -1;
> -    }
> -    return 0;
> +    return VIR_STRDUP(*ifname, ifr.ifr_name);
>  #else
>      return -1;
>  #endif

> diff --git a/src/util/virpci.c b/src/util/virpci.c
> index 5865613..1f19d3f 100644
> --- a/src/util/virpci.c
> +++ b/src/util/virpci.c
> @@ -2268,11 +2264,7 @@ virPCIGetNetName(char *device_link_sysfs_path, char **netname)
>              continue;
>  
>          /* Assume a single directory entry */
> -        *netname = strdup(entry->d_name);
> -        if (!*netname)
> -            virReportOOMError();
> -        else
> -            ret = 0;
> +        ret = VIR_STRDUP(*netname, entry->d_name);
>          break;
>      }

> diff --git a/src/util/virsexpr.c b/src/util/virsexpr.c
> index 23b6781..b17c0d4 100644
> --- a/src/util/virsexpr.c
> +++ b/src/util/virsexpr.c
> @@ -527,13 +511,10 @@ int sexpr_node_copy(const struct sexpr *sexpr, const char *node, char **dst)
>  {
>      const char *val = sexpr_node(sexpr, node);
>  
> -    if (val && *val) {
> -        *dst = strdup(val);
> -        if (!(*dst))
> -            return -1;
> -    } else {
> -        *dst = NULL;
> -    }
> +    if (val && *val)
> +        return VIR_STRDUP(*dst, val);
> +
> +    *dst = NULL;
>      return 0;
>  }


> diff --git a/src/util/virutil.c b/src/util/virutil.c
> index 982d4a3..d3d77b2 100644
> --- a/src/util/virutil.c
> +++ b/src/util/virutil.c
> @@ -547,11 +547,8 @@ virFileResolveLinkHelper(const char *linkpath,
>          if (lstat(linkpath, &st) < 0)
>              return -1;
>  
> -        if (!S_ISLNK(st.st_mode)) {
> -            if (!(*resultpath = strdup(linkpath)))
> -                return -1;
> -            return 0;
> -        }
> +        if (!S_ISLNK(st.st_mode))
> +            return VIR_STRDUP(*resultpath, linkpath);
>      }
>  
>      *resultpath = canonicalize_file_name(linkpath);

> @@ -1503,8 +1502,7 @@ int virFileAbsPath(const char *path, char **abspath)
>      char *buf;
>  
>      if (path[0] == '/') {
> -        if (!(*abspath = strdup(path)))
> -            return -1;
> +        return VIR_STRDUP(*abspath, path);
>      } else {
>          buf = getcwd(NULL, 0);
>          if (buf == NULL)

> @@ -2479,12 +2460,7 @@ virGetWin32DirectoryRoot(char **path)
>          strcpy(windowsdir, "C:\\");
>      }
>  
> -    if (!(*path = strdup(windowsdir))) {
> -        virReportOOMError();
> -        ret = -1;
> -    }
> -
> -    return ret;
> +    return VIR_STRDUP(*path, windowsdir);
>  }
>  
>  

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]