]> diplodocus.org Git - nmh/commitdiff
Add ZERO(p) for the typical memset(p, 0, sizeof *p) dance.
authorRalph Corderoy <ralph@inputplus.co.uk>
Mon, 21 Aug 2017 10:09:02 +0000 (11:09 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Tue, 22 Aug 2017 10:51:14 +0000 (11:51 +0100)
Also seen as memset(&foo->bar_xyzzy, 0, sizeof foo->bar_xyzzy).  I find
it tedious to keep checking the parameters are in agreement when reading
the code.

h/utils.h
sbr/client.c
sbr/datetime.c
sbr/dtimep.l
sbr/fmt_compile.c
sbr/fmt_scan.c
sbr/mts.c
sbr/netsec.c
uip/fmttest.c
uip/replsbr.c

index 19fbdcc..dd3fb43 100644 (file)
--- a/h/utils.h
+++ b/h/utils.h
@@ -31,6 +31,9 @@ void mh_xfree(void *ptr);
 /* Set p to point to newly allocated, zeroed, memory. */
 #define NEW0(p) ((p) = mh_xcalloc(1, sizeof *(p)))
 
+/* Zero the bytes to which p points. */
+#define ZERO(p) memset((p), 0, sizeof *(p))
+
 char *pwd(void);
 char *add(const char *, char *);
 char *addlist(char *, const char *);
index 1a7cb7f..a64461b 100644 (file)
@@ -28,7 +28,7 @@ client (char *server, char *service, char *response, int len_response,
        return NOTOK;
     }
 
-    memset(&hints, 0, sizeof(hints));
+    ZERO(&hints);
 #ifdef AI_ADDRCONFIG
     hints.ai_flags = AI_ADDRCONFIG;
 #endif
index a5f6c77..9ecff53 100644 (file)
@@ -64,7 +64,7 @@ parse_datetime (const char *datetime, const char *zone, int dst,
     int form_1 = 0;
     int items_matched;
 
-    memset(tws, 0, sizeof *tws);
+    ZERO(tws);
     items_matched =
         sscanf (datetime, "%4d%2d%2dT%2d%2d%2d%c",
                 &tws->tw_year, &tws->tw_mon, &tws->tw_mday,
index e9dd815..238af86 100644 (file)
@@ -11,6 +11,7 @@
 %a5000
 %{
 #include <h/nmh.h>
+#include <h/utils.h>
 #include <h/tws.h>
 
   /* Since we're looking at a string at a time, don't worry about
@@ -231,7 +232,7 @@ nl      [ \t\n()]
   char *cp;
   static struct tws tw; 
 
-  memset(&tw,0,sizeof(struct tws));
+  ZERO(&tw);
 
   lexhandle = yy_scan_string(lexstr);
 %}
index 5a4e4b8..389e16c 100644 (file)
@@ -559,7 +559,7 @@ do_name(char *sp, int preprocess)
            CERROR("component used as both date and address");
        }
        if (cm->c_tws) {
-           memset (cm->c_tws, 0, sizeof *cm->c_tws);
+           ZERO(cm->c_tws);
        } else {
            NEW0(cm->c_tws);
        }
index 075b7dd..49fc717 100644 (file)
@@ -989,7 +989,7 @@ fmt_scan (struct format *format, charstring_t scanlp, int width, int *dat,
                *comp->c_tws = *tws;
                comp->c_flags &= ~CF_TRUE;
            } else if ((comp->c_flags & CF_DATEFAB) == 0) {
-               memset (comp->c_tws, 0, sizeof *comp->c_tws);
+               ZERO(comp->c_tws);
                comp->c_flags = CF_TRUE;
            }
            comp->c_flags |= CF_PARSED;
index ae617ce..f6180b0 100644 (file)
--- a/sbr/mts.c
+++ b/sbr/mts.c
@@ -235,7 +235,7 @@ LocalName (int flag)
        gethostname (buf, sizeof(buffer0) - 1);
        /* now fully qualify our name */
 
-       memset(&hints, 0, sizeof(hints));
+        ZERO(&hints);
        hints.ai_flags = AI_CANONNAME;
        hints.ai_family = PF_UNSPEC;
        if (getaddrinfo(buf, NULL, &hints, &res) == 0) {
index 3fcb2cf..58cab1b 100644 (file)
@@ -1217,7 +1217,7 @@ netsec_negotiate_sasl(netsec_context *nsc, const char *mechlist, char **errstr)
      * messages.
      */
 
-    memset(&secprops, 0, sizeof(secprops));
+    ZERO(&secprops);
     secprops.maxbufsize = SASL_MAXRECVBUF;
 
     /*
index 83e5c26..e5323e6 100644 (file)
@@ -336,7 +336,7 @@ main (int argc, char **argv)
      */
 
     if (dupaddrs == 0 || trace) {
-       memset(&cb, 0, sizeof(cb));
+       ZERO(&cb);
        cbp = &cb;
 
        if (dupaddrs == 0) {
index d3ba270..2444aa3 100644 (file)
@@ -205,7 +205,7 @@ finished:
     dat[2] = 0;
     dat[3] = outputlinelen;
     dat[4] = 0;
-    memset(&cb, 0, sizeof(cb));
+    ZERO(&cb);
     cb.formataddr = replformataddr;
     cb.concataddr = replconcataddr;
     fmt_scan (fmt, scanl, i, dat, &cb);