#3941 Remove macro ZERO_STRUCT
Merged 5 years ago by jhrozek. Opened 5 years ago by lslebodn.
SSSD/ lslebodn/sssd zero_struct  into  master

file modified
+2 -2
@@ -3840,7 +3840,7 @@ 

          return EINVAL;

      }

  

-     ZERO_STRUCT(*res);

+     memset(res, 0, sizeof(*res));

  

      if (domain->sysdb->ldb_ts == NULL) {

          return ERR_NO_TS;
@@ -4121,7 +4121,7 @@ 

          return EINVAL;

      }

  

-     ZERO_STRUCT(*res);

+     memset(res, 0, sizeof(*res));

  

      if (domain->sysdb->ldb_ts == NULL) {

          return ERR_NO_TS;

@@ -262,7 +262,7 @@ 

              return ndr_pull_error(ndr, NDR_ERR_RANGE, "value out of range");

          }

          NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, r->id_auth, 6));

-         ZERO_STRUCT(r->sub_auths);

+         memset(&r->sub_auths, 0, sizeof(r->sub_auths));

          for (cntr_sub_auths_0 = 0;

               cntr_sub_auths_0 < r->num_auths;

               cntr_sub_auths_0++) {

@@ -2243,7 +2243,7 @@ 

              type = SYSDB_MEMBER_USER;

              if (dom->subdomain_homedir

                      && attrs->a.user.pw_dir == NULL) {

-                 ZERO_STRUCT(homedir_ctx);

+                 memset(&homedir_ctx, 0, sizeof(homedir_ctx));

                  homedir_ctx.username = attrs->a.user.pw_name;

                  homedir_ctx.uid = attrs->a.user.pw_uid;

                  homedir_ctx.domain = dom->name;

@@ -901,7 +901,7 @@ 

          goto done;

      }

  

-     ZERO_STRUCT(homedir_ctx);

+     memset(&homedir_ctx, 0, sizeof(homedir_ctx));

  

      homedir_ctx.uid = uid;

      homedir_ctx.username = fqname;

file modified
+1 -1
@@ -68,7 +68,7 @@ 

  	struct sigaction act;

  	struct sigaction oldact;

  

- 	ZERO_STRUCT(act);

+ 	memset(&act, 0, sizeof(act));

  

  	act.sa_handler = handler;

  #ifdef SA_RESTART

file modified
-2
@@ -66,8 +66,6 @@ 

  #define NULL 0

  #endif

  

- #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x))

- 

  #define SSSD_MAIN_OPTS SSSD_DEBUG_OPTS

  

  #define SSSD_SERVER_OPTS(uid, gid) \

file modified
+1 -1
@@ -174,7 +174,7 @@ 

      int signum = SIGRTMIN;

      int ret;

  

-     ZERO_STRUCT(sev);

+     memset(&sev, 0, sizeof(sev));

      CatchSignal(signum, watchdog_handler);

  

      sev.sigev_notify = SIGEV_SIGNAL;

It was used just on few places and we directly call memset on many
other places

[~/sssd]$ git grep memset | grep sizeof | wc -l
97

It is not possible to compile sssd on rawhide because samba made such macros public
and it is used in ndr.h

https://bugzilla.redhat.com/show_bug.cgi?id=1671507

OK, it seems odd to export a non-namespaced macro in a public header, but then we can't use this macro either. IIRC our copy of ZERO_STRUCT came from Samba anyway.

btw do you know, from a C perspective, why the ZERO_STRUCT macro would cast the pointer to char?

anyway, LGTM, will run the commit through CI.

OK, it seems odd to export a non-namespaced macro in a public header, but then we can't use this macro either. IIRC our copy of ZERO_STRUCT came from Samba anyway.

But they "recently" changed definition from memset -> memset_s

btw do you know, from a C perspective, why the ZERO_STRUCT macro would cast the pointer to char?

The function memset expect void * and IIRC you can pass any pointer there.
You would need to probably ask original authors :-)

My guessing would be that they wanted to use the macro for const struct ....
Which is far from ideal use-case IMHO.

anyway, LGTM, will run the commit through CI.

Commit 7133c7f fixes this pull-request

Pull-Request has been merged by jhrozek

5 years ago