[libvirt] [PATCH v3 23/34] Adapt to VIR_STRDUP and VIR_STRNDUP in src/test/*

Ján Tomko jtomko at redhat.com
Fri May 10 10:46:58 UTC 2013


On 05/03/2013 04:53 PM, Michal Privoznik wrote:
> ---
>  src/test/test_driver.c | 144 ++++++++++++++++++-------------------------------
>  1 file changed, 52 insertions(+), 92 deletions(-)
> 
> @@ -2060,9 +2057,9 @@ cleanup:
>  }
>  
>  static char *testDomainGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) {
> -    char *ret = strdup("linux");
> -    if (!ret)
> -        virReportOOMError();
> +    char *ret;
> +
> +    ignore_value(VIR_STRDUP_QUIET(ret, "linux"));

s/_QUIET//

>      return ret;
>  }
>  
> @@ -2720,9 +2717,7 @@ static char *testDomainGetSchedulerType(virDomainPtr domain ATTRIBUTE_UNUSED,
>      if (nparams)
>          *nparams = 1;
>  
> -    type = strdup("fair");
> -    if (!type)
> -        virReportOOMError();
> +    ignore_value(VIR_STRDUP_QUIET(type, "fair"));
>  
>      return type;
>  }

s/_QUIET//

> @@ -3551,7 +3540,7 @@ static int testConnectListDefinedInterfaces(virConnectPtr conn, char **const nam
>  
>      return n;
>  
> -no_memory:
> +error:
>      virReportOOMError();

extra virReportOOMError()

>      for (n = 0 ; n < nnames ; n++)
>          VIR_FREE(names[n]);
> @@ -3880,13 +3869,7 @@ static int testStoragePoolObjSetDefaults(virStoragePoolObjPtr pool) {
>      pool->def->allocation = defaultPoolAlloc;
>      pool->def->available = defaultPoolCap - defaultPoolAlloc;
>  
> -    pool->configFile = strdup("\0");
> -    if (!pool->configFile) {
> -        virReportOOMError();
> -        return -1;
> -    }
> -
> -    return 0;
> +    return VIR_STRDUP(pool->configFile, "\0");

Change "\0" to "".

>  }
>  
>  static virDrvOpenStatus testStorageOpen(virConnectPtr conn,
> @@ -5233,9 +5204,7 @@ testStorageVolGetPath(virStorageVolPtr vol) {
>          goto cleanup;
>      }
>  
> -    ret = strdup(privvol->target.path);
> -    if (ret == NULL)
> -        virReportOOMError();
> +    ignore_value(VIR_STRDUP_QUIET(ret, privvol->target.path));

s/_QUIET//

>  
>  cleanup:
>      if (privpool)
> @@ -5393,9 +5362,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev)
>      }
>  
>      if (obj->def->parent) {
> -        ret = strdup(obj->def->parent);
> -        if (!ret)
> -            virReportOOMError();
> +        ignore_value(VIR_STRDUP_QUIET(ret, obj->def->parent));
>      } else {
>          virReportError(VIR_ERR_INTERNAL_ERROR,
>                         "%s", _("no parent for this device"));

s/_QUIET//

> @@ -5460,9 +5427,9 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
>      }
>  
>      for (caps = obj->def->caps; caps && ncaps < maxnames; caps = caps->next) {
> -        names[ncaps] = strdup(virNodeDevCapTypeToString(caps->type));
> -        if (names[ncaps++] == NULL)
> +        if (VIR_STRDUP(names[ncaps], virNodeDevCapTypeToString(caps->type)) < 0)
>              goto cleanup;
> +        ncaps++;
>      }
>      ret = ncaps;
>  

You should either keep the increment in the VIR_STRDUP call or delete
'--ncaps' from the cleanup section.

ACK

Jan




More information about the libvir-list mailing list