[libvirt PATCH 6/8] tests: use g_new0 instead of VIR_ALLOC

Pavel Hrdina phrdina at redhat.com
Thu Oct 8 14:59:36 UTC 2020


On Thu, Oct 08, 2020 at 02:12:12PM +0200, Ján Tomko wrote:
> Signed-off-by: Ján Tomko <jtomko at redhat.com>
> ---
>  tests/viralloctest.c | 18 ++++++------------
>  1 file changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/tests/viralloctest.c b/tests/viralloctest.c
> index c52483998b..785728d6f9 100644
> --- a/tests/viralloctest.c
> +++ b/tests/viralloctest.c
> @@ -117,8 +117,7 @@ testReallocArray(const void *opaque G_GNUC_UNUSED)
>      size_t nt = 10, i;
>      int ret = -1;
>  
> -    if (VIR_ALLOC_N(t, nt) < 0)
> -        return -1;
> +    t = g_new0(testDummyStruct, nt);
>  
>      if (testCheckNonNull(t) < 0)
>          goto cleanup;
> @@ -191,8 +190,7 @@ testExpandArray(const void *opaque G_GNUC_UNUSED)
>      size_t nt = 10, i;
>      int ret = -1;
>  
> -    if (VIR_ALLOC_N(t, nt) < 0)
> -        return -1;
> +    t = g_new0(testDummyStruct, nt);
>  
>      if (testCheckNonNull(t) < 0)
>          goto cleanup;
> @@ -271,8 +269,7 @@ testResizeArray(const void *opaque G_GNUC_UNUSED)
>      size_t nt = 10, at, i;
>      int ret = -1;
>  
> -    if (VIR_ALLOC_N(t, nt) < 0)
> -        return -1;
> +    t = g_new0(testDummyStruct, nt);
>  
>      at = nt;
>  
> @@ -333,8 +330,7 @@ testInsertArray(const void *opaque G_GNUC_UNUSED)
>      int ret = -1;
>      testDummyStruct *n = (void *)0xff;
>  
> -    if (VIR_ALLOC_N(t, nt) < 0)
> -        return -1;
> +    t = g_new0(testDummyStruct, nt);

../tests/viralloctest.c: In function ‘testInsertArray’:
../tests/viralloctest.c:266:7: error: assignment to ‘testDummyStruct **’ from incompatible pointer type ‘testDummyStruct *’ [-Werror=incompatible-pointer-types]
  266 |     t = g_new0(testDummyStruct, nt);
      |       ^
cc1: all warnings being treated as errors

>  
>      if (testCheckNonNull(t) < 0)
>          goto cleanup;
> @@ -398,14 +394,12 @@ testDispose(const void *opaque G_GNUC_UNUSED)
>      nnums = 10;
>      VIR_DISPOSE_N(nums, nnums);
>  
> -    if (VIR_ALLOC(num) < 0)
> -        return -1;
> +    num = g_new0(int, 1);
>  
>      VIR_DISPOSE(num);
>  
>      nnums = 10;
> -    if (VIR_ALLOC_N(nums, nnums) < 0)
> -        return -1;
> +    nums = g_new0(int, nnums);
>  
>      VIR_DISPOSE_N(nums, nnums);
>  
> -- 
> 2.26.2
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20201008/5733d64d/attachment-0001.sig>


More information about the libvir-list mailing list