[libvirt PATCH] sockettest: testMaskNetwork: use g_auto

Ján Tomko posted 1 patch 3 years, 5 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/34ecb093d02623c2a06116aee225c73e9a3caa3d.1605801687.git.jtomko@redhat.com
tests/sockettest.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
[libvirt PATCH] sockettest: testMaskNetwork: use g_auto
Posted by Ján Tomko 3 years, 5 months ago
This has the added benefit of 'gotnet' only being freed after
it was possibly used in the output string.

../src/internal.h:519:27: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  519 | # define fprintf(fh, ...) g_fprintf(fh, __VA_ARGS__)
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~
../tests/sockettest.c:194:9: note: in expansion of macro ‘fprintf’
  194 |         fprintf(stderr, "Expected %s, got %s\n", networkstr, gotnet);
      |         ^~~~~~~

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: Jaroslav Suchanek <jsuchane@redhat.com>
Fixes: ba08c5932e556aa4f5101357127a6224c40e5ebe
---
 tests/sockettest.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/tests/sockettest.c b/tests/sockettest.c
index 3183ca523f..e9654fcebb 100644
--- a/tests/sockettest.c
+++ b/tests/sockettest.c
@@ -175,7 +175,7 @@ static int testMaskNetwork(const char *addrstr,
 {
     virSocketAddr addr;
     virSocketAddr network;
-    char *gotnet = NULL;
+    g_autofree char *gotnet = NULL;
 
     /* Intentionally fill with garbage */
     memset(&network, 1, sizeof(network));
@@ -190,11 +190,9 @@ static int testMaskNetwork(const char *addrstr,
         return -1;
 
     if (STRNEQ(networkstr, gotnet)) {
-        VIR_FREE(gotnet);
         fprintf(stderr, "Expected %s, got %s\n", networkstr, gotnet);
         return -1;
     }
-    VIR_FREE(gotnet);
     return 0;
 }
 
-- 
2.26.2

Re: [libvirt PATCH] sockettest: testMaskNetwork: use g_auto
Posted by Daniel Henrique Barboza 3 years, 5 months ago

On 11/19/20 1:01 PM, Ján Tomko wrote:
> This has the added benefit of 'gotnet' only being freed after
> it was possibly used in the output string.
> 
> ../src/internal.h:519:27: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
>    519 | # define fprintf(fh, ...) g_fprintf(fh, __VA_ARGS__)
>        |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~
> ../tests/sockettest.c:194:9: note: in expansion of macro ‘fprintf’
>    194 |         fprintf(stderr, "Expected %s, got %s\n", networkstr, gotnet);
>        |         ^~~~~~~
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> Reported-by: Jaroslav Suchanek <jsuchane@redhat.com>
> Fixes: ba08c5932e556aa4f5101357127a6224c40e5ebe
> ---

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>

>   tests/sockettest.c | 4 +---
>   1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/tests/sockettest.c b/tests/sockettest.c
> index 3183ca523f..e9654fcebb 100644
> --- a/tests/sockettest.c
> +++ b/tests/sockettest.c
> @@ -175,7 +175,7 @@ static int testMaskNetwork(const char *addrstr,
>   {
>       virSocketAddr addr;
>       virSocketAddr network;
> -    char *gotnet = NULL;
> +    g_autofree char *gotnet = NULL;
>   
>       /* Intentionally fill with garbage */
>       memset(&network, 1, sizeof(network));
> @@ -190,11 +190,9 @@ static int testMaskNetwork(const char *addrstr,
>           return -1;
>   
>       if (STRNEQ(networkstr, gotnet)) {
> -        VIR_FREE(gotnet);
>           fprintf(stderr, "Expected %s, got %s\n", networkstr, gotnet);
>           return -1;
>       }
> -    VIR_FREE(gotnet);
>       return 0;
>   }
>   
>