[libvirt] [PATCH 03/34] conf: use g_strdup in virDomainDiskSet

Ján Tomko posted 34 patches 6 years, 3 months ago
[libvirt] [PATCH 03/34] conf: use g_strdup in virDomainDiskSet
Posted by Ján Tomko 6 years, 3 months ago
Use a temporary variable to allow copying from the
currently set source.

Always return 0 since none of the callers distinguishes
between 0 and 1 propagated from VIR_STRDUP.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/conf/domain_conf.c | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 88e93f6fb8..cd9b6ca993 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2139,15 +2139,10 @@ virDomainDiskGetSource(virDomainDiskDef const *def)
 int
 virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
 {
-    int ret;
-    char *tmp = def->src->path;
-
-    ret = VIR_STRDUP(def->src->path, src);
-    if (ret < 0)
-        def->src->path = tmp;
-    else
-        VIR_FREE(tmp);
-    return ret;
+    char *tmp = g_strdup(src);
+    g_free(def->src->path);
+    def->src->path = tmp;
+    return 0;
 }
 
 
@@ -2174,15 +2169,10 @@ virDomainDiskGetDriver(const virDomainDiskDef *def)
 int
 virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name)
 {
-    int ret;
-    char *tmp = def->driverName;
-
-    ret = VIR_STRDUP(def->driverName, name);
-    if (ret < 0)
-        def->driverName = tmp;
-    else
-        VIR_FREE(tmp);
-    return ret;
+    char *tmp = g_strdup(name);
+    g_free(def->driverName);
+    def->driverName = tmp;
+    return 0;
 }
 
 
-- 
2.21.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 03/34] conf: use g_strdup in virDomainDiskSet
Posted by Michal Privoznik 6 years, 3 months ago
On 10/20/19 2:55 PM, Ján Tomko wrote:
> Use a temporary variable to allow copying from the
> currently set source.
> 
> Always return 0 since none of the callers distinguishes
> between 0 and 1 propagated from VIR_STRDUP.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>   src/conf/domain_conf.c | 26 ++++++++------------------
>   1 file changed, 8 insertions(+), 18 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 88e93f6fb8..cd9b6ca993 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -2139,15 +2139,10 @@ virDomainDiskGetSource(virDomainDiskDef const *def)
>   int
>   virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
>   {
> -    int ret;
> -    char *tmp = def->src->path;
> -
> -    ret = VIR_STRDUP(def->src->path, src);
> -    if (ret < 0)
> -        def->src->path = tmp;
> -    else
> -        VIR_FREE(tmp);
> -    return ret;
> +    char *tmp = g_strdup(src);
> +    g_free(def->src->path);
> +    def->src->path = tmp;
> +    return 0;
>   }


So what I did in my patches was also turn this function to void. Do we 
want that or not?

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 03/34] conf: use g_strdup in virDomainDiskSet
Posted by Ján Tomko 6 years, 3 months ago
On Mon, Oct 21, 2019 at 11:39:14AM +0200, Michal Privoznik wrote:
>On 10/20/19 2:55 PM, Ján Tomko wrote:
>>Use a temporary variable to allow copying from the
>>currently set source.
>>
>>Always return 0 since none of the callers distinguishes
>>between 0 and 1 propagated from VIR_STRDUP.
>>
>>Signed-off-by: Ján Tomko <jtomko@redhat.com>
>>---
>>  src/conf/domain_conf.c | 26 ++++++++------------------
>>  1 file changed, 8 insertions(+), 18 deletions(-)
>>
>>diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>>index 88e93f6fb8..cd9b6ca993 100644
>>--- a/src/conf/domain_conf.c
>>+++ b/src/conf/domain_conf.c
>>@@ -2139,15 +2139,10 @@ virDomainDiskGetSource(virDomainDiskDef const *def)
>>  int
>>  virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src)
>>  {
>>-    int ret;
>>-    char *tmp = def->src->path;
>>-
>>-    ret = VIR_STRDUP(def->src->path, src);
>>-    if (ret < 0)
>>-        def->src->path = tmp;
>>-    else
>>-        VIR_FREE(tmp);
>>-    return ret;
>>+    char *tmp = g_strdup(src);
>>+    g_free(def->src->path);
>>+    def->src->path = tmp;
>>+    return 0;
>>  }
>
>
>So what I did in my patches was also turn this function to void. Do we 
>want that or not?
>

Eventually. I don't think it belongs to the VIR_STRDUP -> g_strdup
conversion.

Jano

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