Hello,

A fresh new 'struct directory' is allocated at three points in dir.c.
This struct has four members: di_name, di_count, di_next and di_prev.
For each instance all struct members are initialised immediately after
the calloc(), so the new memory doesn't need to be cleared first.

- Michael


Index: dir.c
===================================================================
RCS file: /cvs/src/bin/csh/dir.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 dir.c
--- dir.c       26 Dec 2015 13:48:38 -0000      1.21
+++ dir.c       15 Jan 2018 07:21:18 -0000
@@ -116,7 +116,7 @@ dinit(Char *hp)
        }
     }
 
-    dp = xcalloc(1, sizeof(struct directory));
+    dp = xmalloc(sizeof(struct directory));
     dp->di_name = Strsave(cp);
     dp->di_count = 0;
     dhead.di_next = dhead.di_prev = dp;
@@ -351,7 +351,7 @@ dochngd(Char **v, struct command *t)
     }
     else
        cp = dfollow(*v);
-    dp = xcalloc(1, sizeof(struct directory));
+    dp = xmalloc(sizeof(struct directory));
     dp->di_name = cp;
     dp->di_count = 0;
     dp->di_next = dcwd->di_next;
@@ -502,7 +502,7 @@ dopushd(Char **v, struct command *t)
        Char *ccp;
 
        ccp = dfollow(*v);
-       dp = xcalloc(1, sizeof(struct directory));
+       dp = xmalloc(sizeof(struct directory));
        dp->di_name = ccp;
        dp->di_count = 0;
        dp->di_prev = dcwd;

Reply via email to