[PATCH 02/13] virt-aa-helper: Use struct zero initializer instead of memset

Michal Privoznik posted 13 patches 2 years, 6 months ago
[PATCH 02/13] virt-aa-helper: Use struct zero initializer instead of memset
Posted by Michal Privoznik 2 years, 6 months ago
This is similar to the previous commit, except this is for a
different type (vahControl) and also fixes the case where _ctl is
passed not initialized to vah_error() (via ctl pointer so that's
probably why compilers don't complain).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/security/virt-aa-helper.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index 3ee59b32bb..da1e4fc3e4 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -1433,7 +1433,8 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
 int
 main(int argc, char **argv)
 {
-    vahControl _ctl, *ctl = &_ctl;
+    vahControl _ctl = { 0 };
+    vahControl *ctl = &_ctl;
     int rc = -1;
     char *profile = NULL;
     char *include_file = NULL;
@@ -1466,8 +1467,6 @@ main(int argc, char **argv)
     else
         progname++;
 
-    memset(ctl, 0, sizeof(vahControl));
-
     if (vahParseArgv(ctl, argc, argv) != 0)
         vah_error(ctl, 1, _("could not parse arguments"));
 
-- 
2.41.0
Re: [PATCH 02/13] virt-aa-helper: Use struct zero initializer instead of memset
Posted by Claudio Fontana 2 years, 6 months ago
On 8/3/23 12:36, Michal Privoznik wrote:
> This is similar to the previous commit, except this is for a
> different type (vahControl) and also fixes the case where _ctl is
> passed not initialized to vah_error() (via ctl pointer so that's
> probably why compilers don't complain).
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>

Reviewed-by: Claudio Fontana <cfontana@suse.de>

> ---
>  src/security/virt-aa-helper.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
> index 3ee59b32bb..da1e4fc3e4 100644
> --- a/src/security/virt-aa-helper.c
> +++ b/src/security/virt-aa-helper.c
> @@ -1433,7 +1433,8 @@ vahParseArgv(vahControl * ctl, int argc, char **argv)
>  int
>  main(int argc, char **argv)
>  {
> -    vahControl _ctl, *ctl = &_ctl;
> +    vahControl _ctl = { 0 };
> +    vahControl *ctl = &_ctl;
>      int rc = -1;
>      char *profile = NULL;
>      char *include_file = NULL;
> @@ -1466,8 +1467,6 @@ main(int argc, char **argv)
>      else
>          progname++;
>  
> -    memset(ctl, 0, sizeof(vahControl));
> -
>      if (vahParseArgv(ctl, argc, argv) != 0)
>          vah_error(ctl, 1, _("could not parse arguments"));
>