Use calloc, rather than malloc/memset
authorSimon Wilkinson <sxw@your-file-system.com>
Thu, 17 May 2012 07:36:11 +0000 (08:36 +0100)
committerDerrick Brashear <shadow@dementix.org>
Thu, 24 May 2012 15:49:28 +0000 (08:49 -0700)
Rather than doing
a = malloc(sizeof(me));
memset(a, 0, sizeof(me));

Just use
        a = calloc(1, sizeof(me));

This is simpler, shorter, and removes the potential for the size of
the memset not matching the size of the malloc (or the target of the
memset being wrong!)

Where the size is of the form (n * sizeof(me)), we also use
calloc(n, sizeof(me));

Change-Id: Ia0f75665c1031fd2982eee0e1d8c8ebe23d7fbc0
Reviewed-on: http://gerrit.openafs.org/7454
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementix.org>

71 files changed:
src/afsd/afsd.c
src/afsd/afsd_kernel.c
src/auth/cellconfig.c
src/auth/keys.c
src/auth/realms.c
src/auth/token.c
src/bozo/bnode.c
src/bozo/cronbnodeops.c
src/bozo/ezbnodeops.c
src/bozo/fsbnodeops.c
src/bu_utils/fms.c
src/bucoord/commands.c
src/bucoord/config.c
src/bucoord/dsvs.c
src/bucoord/dump_sched.c
src/bucoord/restore.c
src/bucoord/status.c
src/bucoord/tape_hosts.c
src/bucoord/vol_sets.c
src/budb/db_hash.c
src/budb/ol_verify.c
src/budb/procs.c
src/butc/list.c
src/butc/lwps.c
src/butc/tcmain.c
src/butc/tcudbprocs.c
src/gtx/frame.c
src/gtx/keymap.c
src/gtx/textcb.c
src/kauth/rebuild.c
src/libacl/aclprocs.c
src/libadmin/vos/vsprocs.c
src/libafscp/afscp_callback.c
src/libafscp/afscp_dir.c
src/libafscp/afscp_server.c
src/libafscp/afscp_volume.c
src/lwp/iomgr.c
src/lwp/test/selsubs.c
src/ptserver/db_verify.c
src/ptserver/ptuser.c
src/ptserver/testpt.c
src/rx/rx_pthread.c
src/rxkad/rxkad_common.c
src/scout/scout.c
src/sys/pioctl_nt.c
src/tests/fsx.c
src/tools/dumpscan/directory.c
src/tools/dumpscan/pathname.c
src/tools/dumpscan/xf_profile.c
src/tools/dumpscan/xfiles.c
src/tools/rxperf/rxperf.c
src/ubik/beacon.c
src/ubik/disk.c
src/usd/usd_file.c
src/usd/usd_nt.c
src/util/readdir_nt.c
src/venus/afsio.c
src/venus/fstrace.c
src/viced/afsfileprocs.c
src/vlserver/vldb_check.c
src/vol/nuke.c
src/vol/salvaged.c
src/vol/salvsync-server.c
src/vol/vg_cache.c
src/vol/vol-salvage.c
src/vol/volume.c
src/volser/dumpstuff.c
src/volser/vol_split.c
src/volser/volprocs.c
src/volser/voltrans.c
src/volser/vsprocs.c

index bc105c5..ac27729 100644 (file)
@@ -1381,13 +1381,11 @@ SweepAFSCache(int *vFilesFound)
     }
 
     if (cache_dir_filelist == NULL) {
-       cache_dir_filelist = (struct afsd_file_list **)
-           malloc(maxDir * sizeof(*cache_dir_filelist));
+       cache_dir_filelist = calloc(maxDir, sizeof(*cache_dir_filelist));
        if (cache_dir_filelist == NULL) {
            printf("%s: Malloc Failed!\n", rn);
            return (-1);
        }
-       memset(cache_dir_filelist, 0, maxDir * sizeof(*cache_dir_filelist));
     }
 
     if (dir_for_V == NULL) {
@@ -1518,8 +1516,7 @@ BkgHandler(void)
     char srcName[256];
     char dstName[256];
 
-    uspc = (struct afs_uspc_param *)malloc(sizeof(struct afs_uspc_param));
-    memset(uspc, 0, sizeof(struct afs_uspc_param));
+    uspc = calloc(1, sizeof(struct afs_uspc_param));
     memset(srcName, 0, sizeof(srcName));
     memset(dstName, 0, sizeof(dstName));
 
@@ -2077,14 +2074,13 @@ afsd_run(void)
     /*
      * Create and zero the inode table for the desired cache files.
      */
-    inode_for_V = (AFSD_INO_T *) malloc(cacheFiles * sizeof(AFSD_INO_T));
+    inode_for_V = calloc(cacheFiles, sizeof(AFSD_INO_T));
     if (inode_for_V == (AFSD_INO_T *) 0) {
        printf
            ("%s: malloc() failed for cache file inode table with %d entries.\n",
             rn, cacheFiles);
        exit(1);
     }
-    memset(inode_for_V, '\0', (cacheFiles * sizeof(AFSD_INO_T)));
     if (afsd_debug)
        printf("%s: %d inode_for_V entries at 0x%x, %lu bytes\n", rn,
               cacheFiles, inode_for_V, (cacheFiles * sizeof(AFSD_INO_T)));
index 71410db..d074cbf 100644 (file)
@@ -268,15 +268,12 @@ aix_vmount(const char *cacheMountDir)
     int size, error;
 
     size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
-    /* Malloc the vmount structure */
-    if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
+    /* Malloc and zero the vmount structure */
+    if ((vmountp = calloc(1, size)) == NULL) {
        printf("Can't allocate space for the vmount structure (AIX)\n");
        exit(1);
     }
 
-    /* zero out the vmount structure */
-    memset(vmountp, '\0', size);
-
     /* transfer info into the vmount structure */
     vmountp->vmt_revision = VMT_REVISION;
     vmountp->vmt_length = size;
index 9d9d228..896dfd6 100644 (file)
@@ -435,8 +435,7 @@ afsconf_Open(const char *adir)
 
     LOCK_GLOBAL_MUTEX;
     /* zero structure and fill in name; rest is done by internal routine */
-    tdir = (struct afsconf_dir *)malloc(sizeof(struct afsconf_dir));
-    memset(tdir, 0, sizeof(struct afsconf_dir));
+    tdir = calloc(1, sizeof(struct afsconf_dir));
     tdir->name = strdup(adir);
 
     code = afsconf_OpenInternal(tdir, 0, 0);
@@ -697,9 +696,7 @@ afsconf_OpenInternal(struct afsconf_dir *adir, char *cell,
                adir->entries = curEntry;
                curEntry = 0;
            }
-           curEntry =
-               (struct afsconf_entry *)malloc(sizeof(struct afsconf_entry));
-           memset(curEntry, 0, sizeof(struct afsconf_entry));
+           curEntry = calloc(1, sizeof(struct afsconf_entry));
            code =
                ParseCellLine(tbuffer, curEntry->cellInfo.name, linkedcell);
            if (code) {
@@ -808,8 +805,7 @@ afsconf_OpenInternal(struct afsconf_dir *adir, char *cell,
            tp++;
        tp[0] = '\0';
 
-       curAlias = malloc(sizeof(*curAlias));
-       memset(curAlias, 0, sizeof(*curAlias));
+       curAlias = calloc(1, sizeof(*curAlias));
 
        strlcpy(curAlias->aliasInfo.aliasName, aliasPtr, sizeof curAlias->aliasInfo.aliasName);
        strlcpy(curAlias->aliasInfo.realName, tbuffer, sizeof curAlias->aliasInfo.realName);
index ba6843d..938c731 100644 (file)
@@ -1023,11 +1023,10 @@ afsconf_typedKey_blank(void)
 {
     struct afsconf_typedKey *key;
 
-    key = malloc(sizeof(struct afsconf_typedKey));
+    key = calloc(1, sizeof(struct afsconf_typedKey));
     if (key == NULL)
        return NULL;
 
-    memset(key, 0, sizeof(struct afsconf_typedKey));
     rx_atomic_set(&key->refcnt, 1);
 
     return key;
index 8236153..db5fd31 100644 (file)
@@ -438,12 +438,11 @@ _afsconf_LoadRealms(struct afsconf_dir *dir)
     struct afsconf_realms *exclusions = NULL;
 
     /* Create and load the list of local realms. */
-    local_realms = malloc(sizeof(struct afsconf_realms));
+    local_realms = calloc(1, sizeof(struct afsconf_realms));
     if (!local_realms) {
        code = ENOMEM;
        goto cleanup;
     }
-    memset(local_realms, 0, sizeof(struct afsconf_realms));
     opr_queue_Init(&local_realms->list);
     local_realms->compare = compare_realms;
 
@@ -466,12 +465,11 @@ _afsconf_LoadRealms(struct afsconf_dir *dir)
     }
 
     /* Create and load the list of excluded principals. */
-    exclusions = malloc(sizeof(struct afsconf_realms));
+    exclusions = calloc(1, sizeof(struct afsconf_realms));
     if (!exclusions) {
        code = ENOMEM;
        goto cleanup;
     }
-    memset(exclusions, 0, sizeof(struct afsconf_realms));
     opr_queue_Init(&exclusions->list);
     exclusions->compare = compare_principals;
     code = read_local_exclusions(exclusions, dir->name);
index 0f67c39..9d99a1e 100644 (file)
@@ -395,12 +395,10 @@ struct ktc_setTokenData *
 token_buildTokenJar(char * cellname) {
     struct ktc_setTokenData *jar;
 
-    jar = malloc(sizeof(struct ktc_setTokenData));
+    jar = calloc(1, sizeof(struct ktc_setTokenData));
     if (jar == NULL)
        return NULL;
 
-    memset(jar, 0, sizeof(struct ktc_setTokenData));
-
     jar->cell = strdup(cellname);
 
     return jar;
index a79558c..828f6cc 100644 (file)
@@ -338,8 +338,7 @@ bnode_Register(char *atype, struct bnode_ops *aprocs, int anparms)
            break;
     }
     if (!tt) {
-       tt = (struct bnode_type *)malloc(sizeof(struct bnode_type));
-       memset(tt, 0, sizeof(struct bnode_type));
+       tt = calloc(1, sizeof(struct bnode_type));
        tt->next = allTypes;
        allTypes = tt;
        tt->name = atype;
@@ -959,8 +958,7 @@ bnode_NewProc(struct bnode *abnode, char *aexecString, char *coreName,
     code = bnode_ParseLine(aexecString, &tlist);       /* try parsing first */
     if (code)
        return code;
-    tp = (struct bnode_proc *)malloc(sizeof(struct bnode_proc));
-    memset(tp, 0, sizeof(struct bnode_proc));
+    tp = calloc(1, sizeof(struct bnode_proc));
     tp->next = allProcs;
     tp->bnode = abnode;
     tp->comLine = aexecString;
index 3346033..4775f91 100644 (file)
@@ -161,8 +161,7 @@ cron_create(char *ainstance, char *acommand, char *awhen,
        return NULL;
     }
 
-    te = (struct cronbnode *)malloc(sizeof(struct cronbnode));
-    memset(te, 0, sizeof(struct cronbnode));
+    te = calloc(1, sizeof(struct cronbnode));
     code = ktime_ParsePeriodic(awhen, &te->whenToRun);
     if ((code < 0) || (bnode_InitBnode((struct bnode *)te, &cronbnode_ops, ainstance) != 0)) {
        free(te);
index d5ceab0..5c03fe3 100644 (file)
@@ -111,8 +111,7 @@ ez_create(char *ainstance, char *acommand, char *unused1, char *unused2,
        return NULL;
     }
 
-    te = (struct ezbnode *)malloc(sizeof(struct ezbnode));
-    memset(te, 0, sizeof(struct ezbnode));
+    te = calloc(1, sizeof(struct ezbnode));
     if (bnode_InitBnode((struct bnode *)te, &ezbnode_ops, ainstance) != 0) {
        free(te);
        return NULL;
index 7e569a3..4c23e94 100644 (file)
@@ -430,12 +430,11 @@ fs_create(char *ainstance, char *afilecmd, char *avolcmd, char *asalcmd,
        }
     }
 
-    te = (struct fsbnode *)malloc(sizeof(struct fsbnode));
+    te = calloc(1, sizeof(struct fsbnode));
     if (te == NULL) {
        bailout = 1;
        goto done;
     }
-    memset(te, 0, sizeof(struct fsbnode));
     te->filecmd = fileCmdpath;
     te->volcmd = volCmdpath;
     te->salsrvcmd = NULL;
@@ -559,12 +558,11 @@ dafs_create(char *ainstance, char *afilecmd, char *avolcmd,
        }
     }
 
-    te = (struct fsbnode *)malloc(sizeof(struct fsbnode));
+    te = calloc(1, sizeof(struct fsbnode));
     if (te == NULL) {
        bailout = 1;
        goto done;
     }
-    memset(te, 0, sizeof(struct fsbnode));
     te->filecmd = fileCmdpath;
     te->volcmd = volCmdpath;
     te->salsrvcmd = salsrvCmdpath;
index b1e1a21..ecde75d 100644 (file)
@@ -264,11 +264,10 @@ dataBlock(usd_handle_t hTape, afs_int32 reqSize)
     }
 
     if (dB_buffer == 0) {
-       dB_buffer = (char *)malloc(reqSize);
+       dB_buffer = calloc(1, reqSize);
        if (dB_buffer == 0)
            ERROR(-1);
        dB_buffersize = reqSize;
-       memset(dB_buffer, 0, dB_buffersize);
     }
 
     ptr = (int *)dB_buffer;
index ea8b9c0..e702c40 100644 (file)
@@ -107,13 +107,12 @@ getSPEntries(afs_uint32 server, afs_int32 partition,
     }
     /* No server entry added. Add one */
     if (!(*ss)) {
-       *ss = (struct serversort *)malloc(sizeof(struct serversort));
+       *ss = calloc(1, sizeof(struct serversort));
        if (!(*ss)) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            *ss = 0;
            return (BC_NOMEM);
        }
-       memset(*ss, 0, sizeof(struct serversort));
        (*ss)->ipaddr = server;
        (*ss)->next = *serverlist;
        *serverlist = *ss;
@@ -128,7 +127,7 @@ getSPEntries(afs_uint32 server, afs_int32 partition,
     }
     /* No partition entry added. Add one */
     if (!(*ps)) {
-       *ps = (struct partitionsort *)malloc(sizeof(struct partitionsort));
+       *ps = calloc(1, sizeof(struct partitionsort));
        if (!(*ps)) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            free(*ss);
@@ -136,7 +135,6 @@ getSPEntries(afs_uint32 server, afs_int32 partition,
            *ss = 0;
            return (BC_NOMEM);
        }
-       memset(*ps, 0, sizeof(struct partitionsort));
        (*ps)->part = partition;
        (*ps)->next = (*ss)->partitions;
        (*ss)->partitions = *ps;
@@ -309,13 +307,11 @@ EvalVolumeSet2(struct bc_config *aconfig,
 
                if (add) {
                    /* Allocate a volume dump structure and its name */
-                   tvd = (struct bc_volumeDump *)
-                       malloc(sizeof(struct bc_volumeDump));
+                   tvd = calloc(1, sizeof(struct bc_volumeDump));
                    if (!tvd) {
                        afs_com_err(whoami, BC_NOMEM, NULL);
                        ERROR(BC_NOMEM);
                    }
-                   memset(tvd, 0, sizeof(*tvd));
 
                    tvd->name = (char *)malloc(strlen(entries[e].name) + 10);
                    if (!(tvd->name)) {
@@ -579,13 +575,11 @@ EvalVolumeSet1(struct bc_config *aconfig,
                }
 
                total++;
-               tvd = (struct bc_volumeDump *)
-                   malloc(sizeof(struct bc_volumeDump));
+               tvd = calloc(1, sizeof(struct bc_volumeDump));
                if (!tvd) {
                    afs_com_err(whoami, BC_NOMEM, NULL);
                    return (BC_NOMEM);
                }
-               memset(tvd, 0, sizeof(*tvd));
 
                tvd->name = (char *)malloc(strlen(entry.name) + 10);
                if (!(tvd->name)) {
@@ -1186,12 +1180,11 @@ bc_VolRestoreCmd(struct cmd_syndesc *as, void *arock)
 
     for (ti = as->parms[2].items; ti; ti = ti->next) {
        /* build list of volume items */
-       tvol = (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
+       tvol = calloc(1, sizeof(struct bc_volumeDump));
        if (!tvol) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            return BC_NOMEM;
        }
-       memset(tvol, 0, sizeof(struct bc_volumeDump));
 
        tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
        if (!tvol->name) {
@@ -1530,9 +1523,7 @@ bc_VolsetRestoreCmd(struct cmd_syndesc *as, void *arock)
            }
 
            /* Allocate a volumeDump structure and link it in */
-           tvol =
-               (struct bc_volumeDump *)malloc(sizeof(struct bc_volumeDump));
-           memset(tvol, 0, sizeof(struct bc_volumeDump));
+           tvol = calloc(1, sizeof(struct bc_volumeDump));
 
            tvol->name = (char *)malloc(VOLSER_MAXVOLNAME + 1);
            if (!tvol->name) {
@@ -2761,12 +2752,10 @@ DBLookupByVolume(char *volumeName)
            for (i = 0; i < numEntries; i++) {  /*f */
                struct dumpedVol *insPtr, **prevPtr;
 
-               tempPtr =
-                   (struct dumpedVol *)malloc(sizeof(struct dumpedVol));
+               tempPtr = calloc(1, sizeof(struct dumpedVol));
                if (!tempPtr)
                    ERROR(BC_NOMEM);
 
-               memset(tempPtr, 0, sizeof(*tempPtr));
                tempPtr->incTime = volumeEntry[i].clone;
                tempPtr->dumpID = volumeEntry[i].dump;
                strncpy(tempPtr->tapeName, volumeEntry[i].tape,
@@ -2919,13 +2908,12 @@ dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
 
     /* now get the list of tapes */
     for (tapeNumber = dumpEntry.tapes.b; tapeNumber <= dumpEntry.tapes.maxTapes; tapeNumber++) {       /*f */
-       tapeLinkPtr = (struct tapeLink *)malloc(sizeof(struct tapeLink));
+       tapeLinkPtr = calloc(1, sizeof(struct tapeLink));
        if (!tapeLinkPtr) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            ERROR(BC_NOMEM);
        }
 
-       memset(tapeLinkPtr, 0, sizeof(*tapeLinkPtr));
        code = bcdb_FindTapeSeq(dumpid, tapeNumber, &tapeLinkPtr->tapeEntry);
        if (code) {
            code = 0;
@@ -2970,13 +2958,11 @@ dumpInfo(afs_int32 dumpid, afs_int32 detailFlag)
            for (i = 0; i < vl.budb_volumeList_len; i++) {
                link = &tapeLinkPtr->firstVolume;
 
-               volumeLinkPtr =
-                   (struct volumeLink *)malloc(sizeof(struct volumeLink));
+               volumeLinkPtr = calloc(1, sizeof(struct volumeLink));
                if (!volumeLinkPtr) {
                    afs_com_err(whoami, BC_NOMEM, NULL);
                    ERROR(BC_NOMEM);
                }
-               memset(volumeLinkPtr, 0, sizeof(*volumeLinkPtr));
 
                memcpy(&volumeLinkPtr->volumeEntry,
                       &vl.budb_volumeList_val[i],
index e184c49..bcaf017 100644 (file)
@@ -57,12 +57,11 @@ bc_InitConfig(char *apath)
     struct bc_config *tb;
 
     /* initialize global config structure */
-    tb = (struct bc_config *)malloc(sizeof(struct bc_config));
+    tb = calloc(1, sizeof(struct bc_config));
     if (!tb)
        return (BC_NOMEM);
 
     bc_globalConfig = tb;
-    memset(tb, 0, sizeof(struct bc_config));
     tb->path = strdup(apath);
     if (!tb->path) {
        free(tb);
@@ -95,8 +94,7 @@ HostAdd(struct bc_hostEntry **alist, char *aname, afs_int32 aport)
     for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast);
 
     /* tlast now points to the next pointer (or head pointer) we should overwrite */
-    tentry = (struct bc_hostEntry *)malloc(sizeof(struct bc_hostEntry));
-    memset(tentry, 0, sizeof(*tentry));
+    tentry = calloc(1, sizeof(struct bc_hostEntry));
     tentry->name = strdup(aname);
     *tlast = tentry;
     tentry->next = (struct bc_hostEntry *)0;
index 08743a3..74b17db 100644 (file)
@@ -190,8 +190,7 @@ bc_CreateVolumeSet(struct bc_config *aconfig, char *avolName,
        return -1;              /* already exists */
     /* move to end of the list */
 
-    nset = (struct bc_volumeSet *)malloc(sizeof(struct bc_volumeSet));
-    memset(nset, 0, sizeof(*nset));
+    nset = calloc(1, sizeof(struct bc_volumeSet));
     nset->flags = aflags;
     nset->name = strdup(avolName);
     if (aflags & VSFLAG_TEMPORARY) {
@@ -303,8 +302,7 @@ bc_AddVolumeItem(struct bc_config *aconfig, char *avolName, char *ahost,
 
     /* move to end of the list */
     for (tentry = *tlast; tentry; tlast = &tentry->next, tentry = *tlast);
-    tentry = (struct bc_volumeEntry *)malloc(sizeof(struct bc_volumeEntry));
-    memset(tentry, 0, sizeof(*tentry));
+    tentry = calloc(1, sizeof(struct bc_volumeEntry));
     tentry->serverName = strdup(ahost);
     tentry->partname = strdup(apart);
     tentry->name = strdup(avol);
@@ -366,8 +364,7 @@ bc_CreateDumpSchedule(struct bc_config *aconfig, char *adumpName,
     else if (code != -1)
        return -2;              /* name specification error */
 
-    tdump = (struct bc_dumpSchedule *)malloc(sizeof(struct bc_dumpSchedule));
-    memset(tdump, 0, sizeof(*tdump));
+    tdump = calloc(1, sizeof(struct bc_dumpSchedule));
 
     /* prepend this node to the dump schedule list */
     tdump->next = aconfig->dsched;
index 9af5713..ef11ec3 100644 (file)
@@ -424,9 +424,7 @@ bc_ParseDumpSchedule(void)
                    tbuffer);
            return (BC_INTERNALERROR);
        }
-       tds =
-           (struct bc_dumpSchedule *)malloc(sizeof(struct bc_dumpSchedule));
-       memset(tds, 0, sizeof(*tds));
+       tds = calloc(1, sizeof(struct bc_dumpSchedule));
 
        tds->next = (struct bc_dumpSchedule *)0;
        tds->name = strdup(dsname);
index d6acc8c..a0fb9ff 100644 (file)
@@ -270,12 +270,11 @@ bc_Restorer(afs_int32 aindex)
 
        /* If didn't find it, create one and thread into list */
        if (!di) {
-           di = (struct dumpinfo *)malloc(sizeof(struct dumpinfo));
+           di = calloc(1, sizeof(struct dumpinfo));
            if (!di) {
                afs_com_err(whoami, BC_NOMEM, NULL);
                ERROR(BC_NOMEM);
            }
-           memset(di, 0, sizeof(struct dumpinfo));
 
            di->DumpId = dumpDescr->id;
            di->initialDumpId = dumpDescr->initialDumpID;
@@ -292,12 +291,11 @@ bc_Restorer(afs_int32 aindex)
        }
 
        /* Create one and thread into list */
-       vi = (struct volinfo *)malloc(sizeof(struct volinfo));
+       vi = calloc(1, sizeof(struct volinfo));
        if (!vi) {
            afs_com_err(whoami, BC_NOMEM, NULL);
            ERROR(BC_NOMEM);
        }
-       memset(vi, 0, sizeof(struct volinfo));
 
        vi->volname = strdup(vname);
        if (!vi->volname) {
@@ -471,13 +469,11 @@ bc_Restorer(afs_int32 aindex)
 
                        /* Allocate a new tapelist entry if one not found */
                        if (!tle) {
-                           tle = (struct bc_tapeList *)
-                               malloc(sizeof(struct bc_tapeList));
+                           tle = calloc(1, sizeof(struct bc_tapeList));
                            if (!tle) {
                                afs_com_err(whoami, BC_NOMEM, NULL);
                                return (BC_NOMEM);
                            }
-                           memset(tle, 0, sizeof(struct bc_tapeList));
 
                            tle->tapeName = strdup(volumeEntries[ve].tape);
                            if (!tle->tapeName) {
@@ -523,13 +519,11 @@ bc_Restorer(afs_int32 aindex)
                         * Remember the server and partition.
                         */
                        if (!ti) {
-                           ti = (struct bc_tapeItem *)
-                               malloc(sizeof(struct bc_tapeItem));
+                           ti = calloc(1, sizeof(struct bc_tapeItem));
                            if (!ti) {
                                afs_com_err(whoami, BC_NOMEM, NULL);
                                return (BC_NOMEM);
                            }
-                           memset(ti, 0, sizeof(struct bc_tapeItem));
 
                            ti->volumeName = strdup(volumeEntries[ve].name);
                            if (!ti->volumeName) {
@@ -619,14 +613,11 @@ bc_Restorer(afs_int32 aindex)
     }
 
     /* Allocate a list of volumes to restore */
-    tcarray =
-       (struct tc_restoreDesc *)malloc(nentries *
-                                       sizeof(struct tc_restoreDesc));
+    tcarray = calloc(nentries, sizeof(struct tc_restoreDesc));
     if (!tcarray) {
        afs_com_err(whoami, BC_NOMEM, NULL);
        ERROR(BC_NOMEM);
     }
-    memset(tcarray, 0, nentries * sizeof(struct tc_restoreDesc));
 
     /* Fill in the array with the list above */
     i = 0;
index 3ca7cc0..a590dc5 100644 (file)
@@ -86,11 +86,10 @@ createStatusNode(void)
 {
     statusP ptr;
 
-    ptr = (statusP) malloc(sizeof(*ptr));
+    ptr = calloc(1, sizeof(*ptr));
     if (ptr == 0) {
        return (0);
     }
-    memset(ptr, 0, sizeof(*ptr));
 
     /* link it onto the chain of status entries */
     ObtainWriteLock(&statusQueueLock);
index 3fd3b4b..301d375 100644 (file)
@@ -255,10 +255,9 @@ bc_ParseHosts(void)
                    "can't get host info for %s from nameserver or /etc/hosts.",
                    hostName);
        }
-       the = (struct bc_hostEntry *)malloc(sizeof(struct bc_hostEntry));
+       the = calloc(1, sizeof(struct bc_hostEntry));
        if (the == (struct bc_hostEntry *)0)
            return (BC_NOMEM);
-       memset(the, 0, sizeof(struct bc_hostEntry));
        if (tlast) {
            tlast->next = the;
            tlast = the;
index e4824c7..f2042f0 100644 (file)
@@ -484,8 +484,7 @@ bc_ParseVolumeSet(void)
             * the info just read placing it at the head of its queue in the
             * global configuration structure.
             */
-           tvs = (struct bc_volumeSet *)malloc(sizeof(struct bc_volumeSet));
-           memset(tvs, 0, sizeof(*tvs));
+           tvs = calloc(1, sizeof(struct bc_volumeSet));
            tvs->name = strdup(vsname);
 
            /* append to the end */
@@ -511,14 +510,12 @@ bc_ParseVolumeSet(void)
             * spec record, then get the rest of the information regarding
             * the host, and stuff everything into place.
             */
-           tve = (struct bc_volumeEntry *)
-               malloc(sizeof(struct bc_volumeEntry));
+           tve = calloc(1, sizeof(struct bc_volumeEntry));
            if (!tve) {
                afs_com_err(whoami, 0,
                        "Can't malloc() a new volume spec record!");
                return (-1);
            }
-           memset(tve, 0, sizeof(*tve));
            if (bc_ParseHost(serverName, &(tve->server)))
                afs_com_err(whoami, 0, "Can't get required info on host '%s'",
                        serverName);
index af7c643..f9f9385 100644 (file)
@@ -172,8 +172,7 @@ ht_AllocTable(struct ubik_trans *ut, struct memoryHashTable *mht)
     len = nb * nHTBuckets;     /* new hash table length */
 
     mht->size = nb * sizeof(struct memoryHTBlock *);
-    b = mht->blocks = (struct memoryHTBlock **)malloc(mht->size);
-    memset(b, 0, mht->size);
+    b = mht->blocks = calloc(1, mht->size);
 
     for (i = 0; i < nb; i++) {
        b[i] = (struct memoryHTBlock *)malloc(sizeof(struct memoryHTBlock));
@@ -285,8 +284,7 @@ ht_GetTableBlock(struct ubik_trans *ut, struct memoryHashTable *mht,
 
     if (*blocksP == 0) {
        *sizeP = ht_TableSize(length);
-       *blocksP = (struct memoryHTBlock **)malloc(*sizeP);
-       memset(*blocksP, 0, *sizeP);
+       *blocksP = calloc(1, *sizeP);
     }
     n = *sizeP / sizeof(struct memoryHTBlock *);
     if (bi >= n)
index f6cdd35..6196cef 100644 (file)
@@ -699,10 +699,9 @@ verifyBlocks(struct ubik_trans *ut)
        bmsize =
            sizeof(*ablockMap) + (blockEntries[blocktype] -
                                  1) * sizeof(ablockMap->entries[0]);
-       ablockMap = (struct blockMap *)malloc(bmsize);
+       ablockMap = calloc(1, bmsize);
        if (!ablockMap)
            ERROR(BUDB_NOMEM);
-       memset(ablockMap, 0, bmsize);
 
        ablockMap->nEntries = blockEntries[blocktype];
 
@@ -1282,10 +1281,9 @@ verifyDatabase(struct ubik_trans *ut,
 
     /* construct block map - first level is the array of pointers */
     bmsize = nBlocks * sizeof(struct blockMap *);
-    blockMap = (struct blockMap **)malloc(bmsize);
+    blockMap = calloc(1, bmsize);
     if (!blockMap)
        ERROR(BUDB_NOMEM);
-    memset(blockMap, 0, bmsize);
 
     /* verify blocks and construct the block map */
     Log("Read header of every block\n");
index ebc6b69..9258121 100644 (file)
@@ -534,12 +534,13 @@ SendReturnList(struct ubik_trans *ut,
 
     /* Allocate space for the return values if needed and zero it */
     if (eList->budb_dumpList_val == 0) {
-       eList->budb_dumpList_val =
-           (struct budb_dumpEntry *)malloc(e_size * to_return);
+       eList->budb_dumpList_val = calloc(to_return, e_size);
        if (!eList->budb_dumpList_val)
            return (BUDB_NOMEM);
+    } else {
+        memset(eList->budb_dumpList_val, 0, e_size * to_return);
     }
-    memset(eList->budb_dumpList_val, 0, e_size * to_return);
+
     eList->budb_dumpList_len = to_return;
 
     e = (char *)(eList->budb_dumpList_val);
@@ -1040,10 +1041,9 @@ rememberDump(dbadr dumpAddr, void *dumpParam, void *dumpListPtrParam)
     dumpPtr = (struct dump *)dumpParam;
     rockPtr = (struct wantDumpRock *)dumpListPtrParam;
 
-    ptr = (struct chosenDump *)malloc(sizeof(*ptr));
+    ptr = calloc(1, sizeof(*ptr));
     if (!ptr)
        return (0);
-    memset(ptr, 0, sizeof(*ptr));
     ptr->addr = dumpAddr;
     ptr->date = (afs_uint32) ntohl(dumpPtr->created);
 
index 5521ba5..fac79ae 100644 (file)
@@ -60,9 +60,7 @@ void
 CreateNode(struct dumpNode **newNode)
 {
     /* get space */
-    *newNode = (struct dumpNode *)(malloc(sizeof(struct dumpNode)));
-
-    memset(*newNode, 0, sizeof(struct dumpNode));
+    *newNode = calloc(1, sizeof(struct dumpNode));
 
     (*newNode)->next = dumpQHeader->next;
     dumpQHeader->next = *newNode;
index 0383ec8..68f03e3 100644 (file)
@@ -1678,10 +1678,9 @@ Restorer(void *param) {
        allocbufferSize = tapeblocks * BUTM_BLOCKSIZE;  /* This many full tapeblocks */
     }
     bufferBlock = NULL;
-    bufferBlock = (struct TapeBlock *)malloc(allocbufferSize);
+    bufferBlock = calloc(1, allocbufferSize);
     if (!bufferBlock)
        ERROR_EXIT(TC_NOMEMORY);
-    memset(bufferBlock, 0, allocbufferSize);
 
     for (rparams.frag = 0; (rparams.frag < newNode->arraySize);
         rparams.frag++) {
index c082840..fa9b1fd 100644 (file)
@@ -1206,8 +1206,7 @@ main(int argc, char **argv)
      * instead
      */
     if (argc == 1) {
-       ts = (struct cmd_syndesc *)malloc(sizeof(struct cmd_syndesc));
-       memset(ts, 0, sizeof(*ts));
+       ts = calloc(1, sizeof(struct cmd_syndesc));
 
        ti = (struct cmd_item *)malloc(sizeof(struct cmd_item));
        ti->next = 0;
index 3f51bab..d1f0f0a 100644 (file)
@@ -271,11 +271,9 @@ GetDBTape(afs_int32 taskId, Date expires, struct butm_tapeInfo *tapeInfoPtr,
        *wroteLabel = 1;
 
        /* Initialize a tapeEntry for later inclusion into the database */
-       listEntryPtr =
-           (struct tapeEntryList *)malloc(sizeof(struct tapeEntryList));
+       listEntryPtr = calloc(1, sizeof(struct tapeEntryList));
        if (!listEntryPtr)
            ERROR_EXIT(TC_NOMEMORY);
-       memset(listEntryPtr, 0, sizeof(struct tapeEntryList));
 
        /* Remember dumpid so we can delete it later */
        if ((oldTapeLabel.structVersion >= TAPE_VERSION_3)
@@ -871,11 +869,9 @@ readDbTape(struct butm_tapeInfo *tapeInfoPtr,
 
 
     /* Initialize a tapeEntry for later inclusion into the database */
-    listEntryPtr =
-       (struct tapeEntryList *)malloc(sizeof(struct tapeEntryList));
+    listEntryPtr = calloc(1, sizeof(struct tapeEntryList));
     if (!listEntryPtr)
        ERROR_EXIT(TC_NOMEMORY);
-    memset(listEntryPtr, 0, sizeof(struct tapeEntryList));
 
     /* Fill in tape entry so we can save it later */
     strcpy(tapeEntryPtr->name, TNAME(&oldTapeLabel));
@@ -1348,11 +1344,10 @@ saveTextFile(afs_int32 taskId, afs_int32 textType, char *fileName)
     afs_int32 code = 0;
     int tlock = 0;
 
-    ctPtr = (udbClientTextP) malloc(sizeof(*ctPtr));
+    ctPtr = calloc(1, sizeof(*ctPtr));
     if (!ctPtr)
        ERROR_EXIT(TC_NOMEMORY);
 
-    memset(ctPtr, 0, sizeof(*ctPtr));
     ctPtr->textType = textType;
 
     /* lock the text in the database */
index b755b5b..4429c1c 100644 (file)
@@ -187,10 +187,9 @@ gtxframe_AddMenu(struct gtx_frame *aframe, char *alabel, char *astring)
     if (!tmenu) {
        /* Handle everything but the command string, which is handled by the
         * common-case code below */
-       tmenu = (struct gtxframe_menu *)malloc(sizeof(*tmenu));
+       tmenu = calloc(1, sizeof(*tmenu));
        if (tmenu == (struct gtxframe_menu *)0)
            return (-1);
-       memset(tmenu, 0, sizeof(*tmenu));
        tmenu->next = aframe->menus;
        aframe->menus = tmenu;
        tmenu->name = gtx_CopyString(alabel);
@@ -382,7 +381,7 @@ gtxframe_Create(void)
     /*
      * Allocate all the pieces first: frame, keymap, and key state.
      */
-    tframe = (struct gtx_frame *)malloc(sizeof(struct gtx_frame));
+    tframe = calloc(1, sizeof(struct gtx_frame));
     if (tframe == (struct gtx_frame *)0) {
        return ((struct gtx_frame *)0);
     }
@@ -411,7 +410,6 @@ gtxframe_Create(void)
      * Now that all the pieces exist, fill them in and stick them in
      * the right places.
      */
-    memset(tframe, 0, sizeof(struct gtx_frame));
     tframe->keymap = newkeymap;
     tframe->keystate = newkeystate;
     keymap_InitState(tframe->keystate, tframe->keymap);
index 6658136..9cca35c 100644 (file)
 struct keymap_map *
 keymap_Create(void)
 {
-    struct keymap_map *tmap;
-
-    tmap = (struct keymap_map *)malloc(sizeof(struct keymap_map));
-    if (tmap != (struct keymap_map *)0)
-       memset(tmap, 0, sizeof(*tmap));
-    return (tmap);
+    return calloc(1, sizeof(struct keymap_map));
 }
 
 /* make a copy of a string; generic utility */
index 857e153..3e74668 100644 (file)
@@ -110,7 +110,7 @@ gator_textcb_Create(int a_maxEntriesStored, int a_maxCharsPerEntry)
     if (gator_textcb_debug)
        fprintf(stderr, "[%s] Allocating %d bytes for the text buffer\n", rn,
                bytesToAllocate);
-    newBuff = (char *)malloc(bytesToAllocate);
+    newBuff = calloc(1, bytesToAllocate);
     if (newBuff == NULL) {
        fprintf(stderr,
                "[%s] Can't allocate %d bytes for text buffer; errno is %d\n",
@@ -173,11 +173,6 @@ gator_textcb_Create(int a_maxEntriesStored, int a_maxCharsPerEntry)
      * Now, just initialize all the pieces and plug them in.
      */
     if (gator_textcb_debug)
-       fprintf(stderr, "[%s] Zeroing %d bytes in text buffer at %p\n", rn,
-               numBuffBytes, newBuff);
-    memset(newBuff, 0, numBuffBytes);
-
-    if (gator_textcb_debug)
        fprintf(stderr, "[%s] Initializing blank line buffer at %p\n", rn,
                blankLine);
     for (i = 0; i < a_maxCharsPerEntry; i++)
index d52f572..cb55863 100644 (file)
@@ -436,8 +436,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
     nentries =
        (info.st_size -
         (UBIK_HEADERSIZE + header.headerSize)) / sizeof(struct kaentry);
-    entrys = (int *)malloc(nentries * sizeof(int));
-    memset(entrys, 0, nentries * sizeof(int));
+    entrys = calloc(nentries, sizeof(int));
 
     for (i = 0, index = sizeof(header); i < nentries;
         i++, index += sizeof(struct kaentry)) {
index e11cc0a..2db3f98 100644 (file)
@@ -183,9 +183,7 @@ acl_Externalize_pr(int (*func)(idlist *ids, namelist *names), struct acl_accessL
        return (-1);
     acl_NewExternalACL(acl->total, elist);
     nextc = *elist;
-    lids.idlist_val =
-       (afs_int32 *) malloc(ACL_MAXENTRIES * sizeof(afs_int32));
-    memset(lids.idlist_val, 0, ACL_MAXENTRIES * sizeof(afs_int32));
+    lids.idlist_val = calloc(ACL_MAXENTRIES, sizeof(afs_int32));
     lids.idlist_len = acl->total;
     lnames.namelist_len = 0;
     lnames.namelist_val = (prname *) 0;
index 0e5d247..f9e7a45 100644 (file)
@@ -1699,24 +1699,15 @@ UV_ReleaseVolume(afs_cell_handle_p cellHandle, afs_uint32 afromvol,
     cookie.clone = 0;
 
     nservers = entry.nServers / 2;     /* how many to do at once, excluding clone */
-    replicas =
-       (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
-    times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
-    toconns =
-       (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
-                                       nservers + 1);
-    results.manyResults_val =
-       (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
+    replicas = calloc(nservers + 1, sizeof(struct replica));
+    times = calloc(nservers + 1, sizeof(struct release));
+    toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
+    results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
     if (!replicas || !times || !!!results.manyResults_val || !toconns) {
        tst = ADMNOMEM;
        goto fail_UV_ReleaseVolume;
     }
 
-    memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
-    memset(times, 0, (sizeof(struct release) * nservers + 1));
-    memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
-    memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
-
     /* Create a transaction on the cloned volume */
     tst =
        AFSVolTransCreate(fromconn, cloneVolId, afrompart, ITBusy, &fromtid);
index d6c1217..ab98381 100644 (file)
@@ -257,19 +257,15 @@ afscp_ReturnCallBacks(const struct afscp_server *server)
            continue;
        }
        if (!inited) {
-           theFids.AFSCBFids_val = malloc(sizeof(struct AFSFid) * AFSCBMAX);
+           theFids.AFSCBFids_val = calloc(AFSCBMAX, sizeof(struct AFSFid));
            if (!theFids.AFSCBFids_val) {
                return -1;
            }
-           memset(theFids.AFSCBFids_val, 0,
-                  sizeof(struct AFSFid) * AFSCBMAX);
-           theCBs.AFSCBs_val = malloc(sizeof(struct AFSCallBack) * AFSCBMAX);
+           theCBs.AFSCBs_val = calloc(AFSCBMAX, sizeof(struct AFSCallBack));
            if (!theCBs.AFSCBs_val) {
                free(theFids.AFSCBFids_val);
                return -1;
            }
-           memset(theCBs.AFSCBs_val, 0,
-                  sizeof(struct AFSCallBack) * AFSCBMAX);
            inited = 1;
        }
 
index 780c6d9..852a59f 100644 (file)
@@ -207,12 +207,11 @@ afscp_OpenDir(const struct afscp_venusfid *fid)
        afscp_errno = ENOTDIR;
        return NULL;
     }
-    ret = malloc(sizeof(struct afscp_dirstream));
+    ret = calloc(1, sizeof(struct afscp_dirstream));
     if (ret == NULL) {
        afscp_errno = ENOMEM;
        return NULL;
     }
-    memset(ret, 0, sizeof(struct afscp_dirstream));
     memmove(&ret->fid, fid, sizeof(struct afscp_venusfid));
     code = _DirUpdate(ret);
     if (code < 0) {
index abb82e8..57e1107 100644 (file)
@@ -286,11 +286,10 @@ afscp_ServerById(struct afscp_cell *thecell, afsUUID * u)
        }
        thecell->fsservers = newlist;
     }
-    ret = malloc(sizeof(struct afscp_server));
+    ret = calloc(1, sizeof(struct afscp_server));
     if (ret == NULL) {
        return NULL;
     }
-    memset(ret, 0, sizeof(struct afscp_server));
     thecell->fsservers[thecell->nservers] = ret;
     memmove(&ret->id, u, sizeof(afsUUID));
     ret->cell = thecell->id;
@@ -376,11 +375,10 @@ afscp_ServerByAddr(struct afscp_cell *thecell, afs_uint32 addr)
        }
        thecell->fsservers = newlist;
     }
-    ret = malloc(sizeof(struct afscp_server));
+    ret = calloc(1, sizeof(struct afscp_server));
     if (ret == NULL) {
        return NULL;
     }
-    memset(ret, 0, sizeof(struct afscp_server));
     thecell->fsservers[thecell->nservers] = ret;
     ret->cell = thecell->id;
     memset(&uuid, 0, sizeof(uuid));
index 72f2df3..55421b2 100644 (file)
@@ -115,12 +115,11 @@ afscp_VolumeByName(struct afscp_cell *cell, const char *vname,
        afscp_errno = code;
        return NULL;
     }
-    ret = malloc(sizeof(struct afscp_volume));
+    ret = calloc(1, sizeof(struct afscp_volume));
     if (ret == NULL) {
        afscp_errno = ENOMEM;
        return NULL;
     }
-    memset(ret, 0, sizeof(struct afscp_volume));
     strlcpy(ret->name, u.u.name, sizeof(ret->name));
     ret->nservers = 0;
     ret->cell = cell;
@@ -229,12 +228,11 @@ afscp_VolumeById(struct afscp_cell *cell, afs_uint32 id)
        afscp_errno = code;
        return NULL;
     }
-    ret = malloc(sizeof(struct afscp_volume));
+    ret = calloc(1, sizeof(struct afscp_volume));
     if (ret == NULL) {
        afscp_errno = ENOMEM;
        return NULL;
     }
-    memset(ret, 0, sizeof(struct afscp_volume));
     strlcpy(ret->name, u.u.name, sizeof(ret->name));
     ret->nservers = 0;
     ret->cell = cell;
index 2ed325a..8f0a7bc 100644 (file)
@@ -176,9 +176,8 @@ static struct IoRequest *NewRequest(void)
 
     if ((request=iorFreeList))
        iorFreeList = (struct IoRequest *) (request->next);
-    else request = (struct IoRequest *) malloc(sizeof(struct IoRequest));
+    else request = calloc(1, sizeof(struct IoRequest));
 
-    memset((char*)request, 0, sizeof(struct IoRequest));
     return request;
 }
 
index 0567851..efc16a5 100644 (file)
@@ -38,8 +38,7 @@
 fd_set *
 IOMGR_AllocFDSet(void)
 {
-    fd_set *tmp = (fd_set *) malloc(sizeof(fd_set));
-    memset(tmp, 0, sizeof(fd_set));
+    fd_set *tmp = calloc(1, sizeof(fd_set));
     return tmp;
 }
 
index 6a04ab1..fde0252 100644 (file)
@@ -1253,8 +1253,7 @@ CheckPrDatabase(struct misc_data *misc)   /* info & statistics */
     }
     if (misc->verbose)
        printf("Database has %d entries\n", n);
-    map = (char *)malloc(n);
-    memset(map, 0, n);
+    map = calloc(1, n);
     misc->nEntries = n;
 
     if (misc->verbose) {
@@ -1282,14 +1281,13 @@ CheckPrDatabase(struct misc_data *misc) /* info & statistics */
 #else
     n = ((misc->maxId > misc->maxForId) ? misc->maxId : misc->maxForId);
     misc->idRange = n - misc->minId + 1;
-    misc->idmap = (afs_int32 *) malloc(misc->idRange * sizeof(afs_int32));
+    misc->idmap = calloc(misc->idRange, sizeof(afs_int32));
     if (!misc->idmap) {
        afs_com_err(whoami, 0, "Unable to malloc space for max ids of %d",
                misc->idRange);
        code = -1;
        goto abort;
     }
-    memset(misc->idmap, 0, misc->idRange * sizeof(misc->idmap[0]));
 #endif /* SUPERGROUPS */
 
     if (misc->verbose) {
@@ -1480,12 +1478,11 @@ inccount(struct idused **idmapp, int id)
        idmapp = &idmap->idnext;
     }
     if (!idmap) {
-       idmap = (struct idused *)malloc(sizeof *idmap);
+       idmap = calloc(1, sizeof *idmap);
        if (!idmap) {
            perror("idmap");
            exit(1);
        }
-       memset(idmap, 0, sizeof idmap);
        idmap->idstart = id & ~(IDCOUNT - 1);
        idmap->idnext = *idmapp;
        *idmapp = idmap;
index 29114cd..d277091 100644 (file)
@@ -63,11 +63,10 @@ AllocateIdHash(struct idhash **aidhash)
 {
     struct idhash *idhash;
 
-    idhash = (struct idhash *)malloc(sizeof(struct idhash));
+    idhash = calloc(1, sizeof(struct idhash));
     if (!idhash) {
        return ENOMEM;
     }
-    memset((void *)idhash, 0, sizeof(struct idhash));
     *aidhash = idhash;
     return 0;
 }
index cf8a68f..636ae5b 100644 (file)
@@ -489,19 +489,14 @@ TestManyMembers(struct cmd_syndesc *as, void *arock)
 
     srandom(seed);
 
-    users = (afs_int32 *) malloc(number * sizeof(afs_int32));
-    groups = (afs_int32 *) malloc(number * sizeof(afs_int32));
-    filled = (char *)malloc(number * sizeof(char));
-    cleaned = (char *)malloc(number * sizeof(char));
-    population = (char *)malloc(sqr(number) * sizeof(char));
+    users = calloc(number, sizeof(afs_int32));
+    groups = calloc(number, sizeof(afs_int32));
+    filled = calloc(number, sizeof(char));
+    cleaned = calloc(number, sizeof(char));
+    population = calloc(sqr(number), sizeof(char));
 
     nFilled = 0;
-    memset(filled, 0, number);
     nCleaned = 0;
-    memset(cleaned, 0, number);
-    memset(population, 0, sqr(number));
-    memset(users, 0, number * sizeof(afs_int32));
-    memset(groups, 0, number * sizeof(afs_int32));
 
     ownerUser = lastGroup = 0;
     groupOwners = (afs_int32 *) malloc(number * sizeof(afs_int32));
index bf5cbe6..a8a8ef0 100644 (file)
@@ -431,9 +431,8 @@ rxi_Sendmsg(osi_socket socket, struct msghdr *msg_p, int flags)
 
 struct rx_ts_info_t * rx_ts_info_init(void) {
     struct rx_ts_info_t * rx_ts_info;
-    rx_ts_info = (rx_ts_info_t *) malloc(sizeof(rx_ts_info_t));
+    rx_ts_info = calloc(1, sizeof(rx_ts_info_t));
     osi_Assert(rx_ts_info != NULL && pthread_setspecific(rx_ts_info_key, rx_ts_info) == 0);
-    memset(rx_ts_info, 0, sizeof(rx_ts_info_t));
 #ifdef RX_ENABLE_TSFPQ
     queue_Init(&rx_ts_info->_FPQ);
 
index f9a80a6..75a8b26 100644 (file)
@@ -114,9 +114,8 @@ rxkad_Init(void) {
 rxkad_stats_t *
 rxkad_thr_stats_init(void) {
     rxkad_stats_t * rxkad_stats;
-    rxkad_stats = (rxkad_stats_t *)malloc(sizeof(rxkad_stats_t));
+    rxkad_stats = calloc(1, sizeof(rxkad_stats_t));
     osi_Assert(rxkad_stats != NULL && pthread_setspecific(rxkad_stats_key,rxkad_stats) == 0);
-    memset(rxkad_stats,0,sizeof(rxkad_stats_t));
     RXKAD_GLOBAL_STATS_LOCK;
     DLL_INSERT_TAIL(rxkad_stats, rxkad_global_stats.first, rxkad_global_stats.last, next, prev);
     RXKAD_GLOBAL_STATS_UNLOCK;
index b65865d..8c50476 100644 (file)
@@ -1699,14 +1699,13 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg)
      * watching.
      */
     sktbytes = a_numservers * sizeof(struct sockaddr_in);
-    FSSktArray = (struct sockaddr_in *)malloc(sktbytes);
+    FSSktArray = calloc(1, sktbytes);
     if (FSSktArray == (struct sockaddr_in *)0) {
        fprintf(stderr,
                "[%s] Can't malloc() %d sockaddrs (%d bytes) for the given servers\n",
                rn, a_numservers, sktbytes);
        scout_CleanExit(-1);
     }
-    memset(FSSktArray, 0, sktbytes);
 
     /*
      * Sweep through the server names provided, filling in the socket
@@ -1742,13 +1741,12 @@ execute_scout(int a_numservers, struct cmd_item *a_srvname, int a_pkg)
      * Create the set of mini-lines, one per server.
      */
     mini_line_bytes = a_numservers * sizeof(struct mini_line);
-    mini_lines = (struct mini_line *)malloc(mini_line_bytes);
+    mini_lines = calloc(1, mini_line_bytes);
     if (mini_lines == (struct mini_line *)0) {
        fprintf(stderr, "[%s] Can't malloc() %d bytes for %d screen lines\n",
                rn, mini_line_bytes, a_numservers);
        return (-1);
     }
-    memset(mini_lines, 0, mini_line_bytes);
 
     /*
      * Set up each line in the mini_lines, creating and initializing
index c2f73af..7654fc5 100644 (file)
@@ -186,12 +186,10 @@ RDR_Ready(void)
     //
     // Allocate a response buffer.
     //
-    respBuffer = (AFSDriverStatusRespCB *)malloc( sizeof( AFSDriverStatusRespCB));
+    respBuffer = calloc(1, sizeof( AFSDriverStatusRespCB));
     if( respBuffer)
     {
 
-       memset( respBuffer, '\0', sizeof( AFSDriverStatusRespCB));
-
         if( !DeviceIoControl( hDevHandle,
                               IOCTL_AFS_STATUS_REQUEST,
                               NULL,
index e1dffd1..2ce2ee0 100644 (file)
@@ -1017,10 +1017,8 @@ main(int argc, char **argv)
     original_buf = (char *)malloc(maxfilelen);
     for (i = 0; i < maxfilelen; i++)
        original_buf[i] = random() % 256;
-    good_buf = (char *)malloc(maxfilelen);
-    bzero(good_buf, maxfilelen);
-    temp_buf = (char *)malloc(maxoplen);
-    bzero(temp_buf, maxoplen);
+    good_buf = calloc(1, maxfilelen);
+    temp_buf = calloc(1, maxoplen);
     if (lite) {                        /* zero entire existing file */
        ssize_t written;
 
index f9ffac2..a3b9d3e 100644 (file)
@@ -256,9 +256,8 @@ afs_uint32 Dir_Init(struct dir_state **dsp)
 {
   afs_uint32 r;
 
-  *dsp = malloc(sizeof(struct dir_state));
+  *dsp = calloc(1, sizeof(struct dir_state));
   if (!*dsp) return ENOMEM;
-  memset(*dsp, 0, sizeof(struct dir_state));
   if ((r = allocpage(*dsp, DPHE))) return r;
   (*dsp)->dh = (afs_dir_header *)((*dsp)->page);
   return 0;
index 1afdb8e..61f7a86 100644 (file)
@@ -48,9 +48,8 @@ get_vhash_ent(path_hashinfo * phi, afs_uint32 vnode, int make)
     for (vhe = phi->hash_table[key]; vhe && vhe->vnode != vnode;
         vhe = vhe->next);
     if (make && !vhe) {
-       vhe = (vhash_ent *) malloc(sizeof(vhash_ent));
+       vhe = calloc(1, sizeof(vhash_ent));
        if (vhe) {
-           memset(vhe, 0, sizeof(vhash_ent));
            vhe->vnode = vnode;
            vhe->next = phi->hash_table[key];
            phi->hash_table[key] = vhe;
@@ -71,10 +70,9 @@ volhdr_cb(afs_vol_header * hdr, XFILE * X, void *refcon)
        for (phi->hash_size = 1; nfiles > BUCKET_SIZE;
             phi->hash_size++, nfiles >>= 1);
        hsize = (1 << phi->hash_size);
-       phi->hash_table = (vhash_ent **) malloc(hsize * sizeof(vhash_ent *));
+       phi->hash_table = calloc(hsize ,sizeof(vhash_ent *));
        if (!phi->hash_table)
            return ENOMEM;
-       memset(phi->hash_table, 0, hsize * sizeof(vhash_ent *));
        return 0;
     } else {
        if (phi->p->cb_error)
index d24c72f..c926693 100644 (file)
@@ -136,10 +136,9 @@ xfopen_profile(XFILE * X, int flag, char *xname, char *profile)
     PFILE *PF;
     afs_uint32 err;
 
-    PF = malloc(sizeof(*PF));
+    PF = calloc(1, sizeof(*PF));
     if (!PF)
        return ENOMEM;
-    memset(PF, 0, sizeof(*PF));
 
     err = xfopen(&PF->profile, O_RDWR | O_CREAT | O_TRUNC, profile);
     if (err) {
index 527f89b..eaad96f 100644 (file)
@@ -198,9 +198,8 @@ xfregister(char *name, afs_uint32(*do_on) (XFILE *, int, char *))
 {
     struct xftype *x;
 
-    if (!(x = (struct xftype *)malloc(sizeof(struct xftype))))
+    if (!(x = calloc(1, sizeof(struct xftype))))
        return ENOMEM;
-    memset(x, 0, sizeof(*x));
     x->next = xftypes;
     x->name = name;
     x->do_on = do_on;
index 3367fd2..b20f91f 100644 (file)
@@ -692,8 +692,7 @@ do_client(const char *server, short port, char *filename, afs_int32 command,
     void *status;
 #endif
 
-    params = malloc(sizeof(struct client_data));
-    memset(params, 0, sizeof(struct client_data));
+    params = calloc(1, sizeof(struct client_data));
 
 #ifdef AFS_NT40_ENV
     if (afs_winsockInit() < 0) {
index d12274d..9fdcfc3 100644 (file)
@@ -293,8 +293,7 @@ ubeacon_InitServerListCommon(afs_uint32 ame, struct afsconf_cell *info,
        for (i = 0; i < info->numServers; i++) {
            if (i == me)
                continue;
-           ts = (struct ubik_server *)malloc(sizeof(struct ubik_server));
-           memset(ts, 0, sizeof(struct ubik_server));
+           ts = calloc(1, sizeof(struct ubik_server));
            ts->next = ubik_servers;
            ubik_servers = ts;
            ts->addr[0] = info->hostAddr[i].sin_addr.s_addr;
@@ -326,8 +325,7 @@ ubeacon_InitServerListCommon(afs_uint32 ame, struct afsconf_cell *info,
        while ((servAddr = *aservers++)) {
            if (i >= MAXSERVERS)
                return UNHOSTS; /* too many hosts */
-           ts = (struct ubik_server *)malloc(sizeof(struct ubik_server));
-           memset(ts, 0, sizeof(struct ubik_server));
+           ts = calloc(1, sizeof(struct ubik_server));
            ts->next = ubik_servers;
            ubik_servers = ts;
            ts->addr[0] = servAddr;     /* primary address in  net byte order */
index 17685ec..ec8f479 100644 (file)
@@ -238,9 +238,8 @@ udisk_Init(int abuffers)
     /* Initialize the venus buffer system. */
     int i;
     struct buffer *tb;
-    Buffers = (struct buffer *)malloc(abuffers * sizeof(struct buffer));
-    memset(Buffers, 0, abuffers * sizeof(struct buffer));
-    BufferData = (char *)malloc(abuffers * UBIK_PAGESIZE);
+    Buffers = calloc(abuffers, sizeof(struct buffer));
+    BufferData = malloc(abuffers * UBIK_PAGESIZE);
     nbuffers = abuffers;
     for (i = 0; i < PHSIZE; i++)
        phTable[i] = 0;
@@ -839,8 +838,7 @@ udisk_begin(struct ubik_dbase *adbase, int atype, struct ubik_trans **atrans)
        if (code)
            return code;
     }
-    tt = (struct ubik_trans *)malloc(sizeof(struct ubik_trans));
-    memset(tt, 0, sizeof(struct ubik_trans));
+    tt = calloc(1, sizeof(struct ubik_trans));
     tt->dbase = adbase;
     tt->next = adbase->activeTrans;
     adbase->activeTrans = tt;
index fb20661..f66df08 100644 (file)
@@ -325,8 +325,7 @@ usd_FileOpen(const char *path, int flags, int mode, usd_handle_t * usdP)
     if (fd == -1)
        return errno;
 
-    usd = (usd_handle_t) malloc(sizeof(*usd));
-    memset(usd, 0, sizeof(*usd));
+    usd = calloc(1, sizeof(*usd));
     usd->handle = (void *)(intptr_t)fd;
     usd->read = usd_FileRead;
     usd->write = usd_FileWrite;
@@ -396,8 +395,7 @@ usd_FileStandardInput(usd_handle_t * usdP)
     if (usdP)
        *usdP = NULL;
 
-    usd = (usd_handle_t) malloc(sizeof(*usd));
-    memset(usd, 0, sizeof(*usd));
+    usd = calloc(1, sizeof(*usd));
     usd->handle = (void *)((unsigned long)0);
     usd->read = usd_FileRead;
     usd->write = usd_FileWrite;
@@ -425,8 +423,7 @@ usd_FileStandardOutput(usd_handle_t * usdP)
     if (usdP)
        *usdP = NULL;
 
-    usd = (usd_handle_t) malloc(sizeof(*usd));
-    memset(usd, 0, sizeof(*usd));
+    usd = calloc(1, sizeof(*usd));
     usd->handle = (void *)((unsigned long)1);
     usd->read = usd_FileRead;
     usd->write = usd_FileWrite;
index 41786b5..28dfa54 100644 (file)
@@ -466,9 +466,7 @@ usd_DeviceOpen(const char *path, int oflag, int pmode, usd_handle_t * usdP)
     if (devhandle == INVALID_HANDLE_VALUE)
        return nterr_nt2unix(GetLastError(), EIO);
 
-    usd = (usd_handle_t) malloc(sizeof(*usd));
-    memset(usd, 0, sizeof(*usd));
-
+    usd = calloc(1, sizeof(*usd));
 
     _ASSERT(sizeof(devhandle) <= sizeof(usd->handle));
     usd->handle = (void *)devhandle;
@@ -524,8 +522,7 @@ usd_DeviceStandardInput(usd_handle_t * usdP)
     if (usdP)
        *usdP = NULL;
 
-    usd = (usd_handle_t) malloc(sizeof(*usd));
-    memset(usd, 0, sizeof(*usd));
+    usd = calloc(1, sizeof(*usd));
     usd->handle = (void *)0;
     usd->read = usd_DeviceRead;
     usd->write = usd_DeviceWrite;
@@ -552,8 +549,7 @@ usd_DeviceStandardOutput(usd_handle_t * usdP)
     if (usdP)
        *usdP = NULL;
 
-    usd = (usd_handle_t) malloc(sizeof(*usd));
-    memset(usd, 0, sizeof(*usd));
+    usd = calloc(1, sizeof(*usd));
     usd->handle = (void *)1;
     usd->read = usd_DeviceRead;
     usd->write = usd_DeviceWrite;
index 7a18f01..ff093cd 100644 (file)
@@ -75,11 +75,10 @@ opendir(const char *path)
        }
     }
 
-    tDir = (DIR *) malloc(sizeof(DIR));
+    tDir = calloc(1, sizeof(DIR));
     if (!tDir) {
        errno = ENOMEM;
     } else {
-       memset((void *)tDir, 0, sizeof(*tDir));
        tDir->h = tH;
        tDir->data = tData;
     }
index 3f35b69..421f355 100644 (file)
@@ -431,13 +431,12 @@ GetVenusFidByFid(char *fidString, char *cellName, int onlyRW,
     struct afscp_volume *avolp;
 
     if (*avfpp == NULL) {
-       *avfpp = malloc(sizeof(struct afscp_venusfid));
+       *avfpp = calloc(1, sizeof(struct afscp_venusfid));
        if ( *avfpp == NULL ) {
            code = ENOMEM;
            return code;
        }
     }
-    memset(*avfpp, 0, sizeof(struct afscp_venusfid));
 
     if (cellName == NULL) {
        (*avfpp)->cell = afscp_DefaultCell();
@@ -747,14 +746,13 @@ readFile(struct cmd_syndesc *as, void *unused)
     Len <<= 32;
     Len += OutStatus.Length;
     ZeroInt64(Pos);
-    buf = (char *) malloc(bufflen * sizeof(char));
+    buf = calloc(bufflen, sizeof(char));
     if (buf == NULL) {
        code = ENOMEM;
        afs_com_err(pnp, code, "(cannot allocate buffer)");
        afscp_FreeFid(avfp);
        return code;
     }
-    memset(buf, 0, bufflen * sizeof(char));
     length = Len;
     while (!code && NonZeroInt64(length)) {
        if (length > bufflen)
@@ -951,7 +949,7 @@ writeFile(struct cmd_syndesc *as, void *unused)
      */
     Len = 0;
     while (Len < WRITEBUFLEN) {
-       tbuf = (struct wbuf *)malloc(sizeof(struct wbuf));
+       tbuf = calloc(1, sizeof(struct wbuf));
        if (tbuf == NULL) {
            if (!bufchain) {
                code = ENOMEM;
@@ -962,7 +960,6 @@ writeFile(struct cmd_syndesc *as, void *unused)
            }
            break;
        }
-       memset(tbuf, 0, sizeof(struct wbuf));
        tbuf->buflen = BUFFLEN;
        if (synthesize) {
            afs_int64 ll, l = tbuf->buflen;
index 11c560b..b8ce877 100644 (file)
@@ -674,8 +674,7 @@ icl_DumpKernel(FILE *outFilep, char *setname)
            found++;
            if (dummy > bufferSize)     /* find biggest log */
                bufferSize = dummy;
-           lip = (struct logInfo *)malloc(sizeof(struct logInfo));
-           memset(lip, 0, sizeof(*lip));
+           lip = calloc(1, sizeof(struct logInfo));
            lip->nextp = allInfo;
            allInfo = lip;
            lip->name = strdup(tname);
@@ -691,8 +690,7 @@ icl_DumpKernel(FILE *outFilep, char *setname)
                break;
            if (dummy > bufferSize)     /* find biggest log */
                bufferSize = dummy;
-           lip = (struct logInfo *)malloc(sizeof(struct logInfo));
-           memset(lip, 0, sizeof(*lip));
+           lip = calloc(1, sizeof(struct logInfo));
            lip->nextp = allInfo;
            allInfo = lip;
            lip->name = strdup(tname);
@@ -1639,14 +1637,13 @@ GetBulkSetInfo(void)
        sizeof(afs_icl_bulkSetinfo_t) + (ICL_RPC_MAX_SETS -
                                         1) * sizeof(afs_icl_setinfo_t);
     if (!setInfo) {
-       setInfo = (afs_icl_bulkSetinfo_t *) malloc(infoSize);
+       setInfo = calloc(1, infoSize);
        if (!setInfo) {
            (void)fprintf(stderr,
                          "Could not allocate the memory for bulk set info structure\n");
            exit(1);
        }
     }
-    memset(setInfo, 0, infoSize);
 
     return setInfo;
 }
@@ -1660,7 +1657,7 @@ GetBulkLogInfo(void)
        sizeof(afs_icl_bulkLoginfo_t) + (ICL_RPC_MAX_LOGS -
                                         1) * sizeof(afs_icl_loginfo_t);
     if (!logInfo) {
-       logInfo = (afs_icl_bulkLoginfo_t *) malloc(infoSize);
+       logInfo = calloc(1, infoSize);
        if (!logInfo) {
            (void)fprintf(stderr,
                          "Could not allocate the memory for bulk log info structure\n");
@@ -1668,7 +1665,6 @@ GetBulkLogInfo(void)
        }
     }
 
-    memset(logInfo, 0, infoSize);
     return logInfo;
 }
 
index 4aeae1a..1ba3cda 100644 (file)
@@ -2658,22 +2658,18 @@ SRXAFS_InlineBulkStatus(struct rx_call * acall, struct AFSCBFids * Fids,
     }
 
     /* allocate space for return output parameters */
-    OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
-       malloc(nfiles * sizeof(struct AFSFetchStatus));
+    OutStats->AFSBulkStats_val = calloc(nfiles, sizeof(struct AFSFetchStatus));
     if (!OutStats->AFSBulkStats_val) {
        ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
     }
     OutStats->AFSBulkStats_len = nfiles;
-    CallBacks->AFSCBs_val = (struct AFSCallBack *)
-       malloc(nfiles * sizeof(struct AFSCallBack));
+    CallBacks->AFSCBs_val = calloc(nfiles, sizeof(struct AFSCallBack));
     if (!CallBacks->AFSCBs_val) {
        ViceLogThenPanic(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
     }
     CallBacks->AFSCBs_len = nfiles;
 
     /* Zero out return values to avoid leaking information on partial succes */
-    memset(OutStats->AFSBulkStats_val, 0, nfiles * sizeof(struct AFSFetchStatus));
-    memset(CallBacks->AFSCBs_val, 0, nfiles * sizeof(struct AFSCallBack));
     memset(Sync, 0, sizeof(*Sync));
 
     if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon, &thost))) {
index f027e77..005b1ec 100644 (file)
@@ -1182,8 +1182,7 @@ WorkerBee(struct cmd_syndesc *as, void *arock)
     }
 
     maxentries = (header.vital_header.eofPtr / sizeof(vlentry)) + 1;
-    record = (struct er *)malloc(maxentries * sizeof(struct er));
-    memset(record, 0, (maxentries * sizeof(struct er)));
+    record = calloc(maxentries, sizeof(struct er));
     memset(serveraddrs, 0, sizeof(serveraddrs));
 
     /* Will fill in the record array of entries it found */
index b0b4262..c8c2ed8 100644 (file)
@@ -65,8 +65,7 @@ NukeProc(struct ViceInodeInfo *ainfo, afs_uint32 avolid, void *arock)
        return 0;               /* don't want this one */
     /* record the info */
     if (!*allInodes || (*allInodes)->freePtr >= MAXATONCE) {
-       ti = (struct ilist *)malloc(sizeof(struct ilist));
-       memset(ti, 0, sizeof(*ti));
+       ti = calloc(1, sizeof(struct ilist));
        ti->next = *allInodes;
        *allInodes = ti;
     } else
index cd89a0d..dbd6930 100644 (file)
@@ -503,9 +503,8 @@ SalvageServer(int argc, char **argv)
      * the salvager daemon */
     ObtainSharedSalvageLock();
 
-    child_slot = (int *) malloc(Parallel * sizeof(int));
+    child_slot = calloc(Parallel, sizeof(int));
     osi_Assert(child_slot != NULL);
-    memset(child_slot, 0, Parallel * sizeof(int));
 
     /* initialize things */
     VOptDefaults(salvageServer, &opts);
index 67f50d1..d9343bc 100644 (file)
@@ -890,14 +890,12 @@ AllocNode(struct SalvageQueueNode ** node_out)
     int code = 0;
     struct SalvageQueueNode * node;
 
-    *node_out = node = (struct SalvageQueueNode *)
-       malloc(sizeof(struct SalvageQueueNode));
+    *node_out = node = calloc(1, sizeof(struct SalvageQueueNode));
     if (node == NULL) {
        code = 1;
        goto done;
     }
 
-    memset(node, 0, sizeof(struct SalvageQueueNode));
     node->type = SALVSYNC_VOLGROUP_PARENT;
     node->state = SALVSYNC_STATE_UNKNOWN;
 
index 109b8e5..708bd3d 100644 (file)
@@ -150,19 +150,12 @@ VVGCache_PkgShutdown(void)
 static int
 _VVGC_entry_alloc(VVGCache_entry_t ** entry_out)
 {
-    int code = 0;
-    VVGCache_entry_t * ent;
-
-    *entry_out = ent = malloc(sizeof(VVGCache_entry_t));
-    if (ent == NULL) {
-       code = ENOMEM;
-       goto error;
-    }
+    *entry_out = calloc(1, sizeof(VVGCache_entry_t));
 
-    memset(ent, 0, sizeof(*ent));
+    if (*entry_out == NULL)
+       return ENOMEM;
 
- error:
-    return code;
+    return 0;
 }
 
 /**
index 7146692..0f189d9 100644 (file)
@@ -486,12 +486,11 @@ SalvageFileSysParallel(struct DiskPartition64 *partP)
 
     if (partP) {
        /* We have a partition to salvage. Copy it into thisjob */
-       thisjob = (struct job *)malloc(sizeof(struct job));
+       thisjob = calloc(1, sizeof(struct job));
        if (!thisjob) {
            Log("Can't salvage '%s'. Not enough memory\n", partP->name);
            return;
        }
-       memset(thisjob, 0, sizeof(struct job));
        thisjob->partP = partP;
        thisjob->jobnumb = jobcount;
        jobcount++;
@@ -2185,10 +2184,8 @@ SalvageVolumeHeaderFile(struct SalvInfo *salvinfo, struct InodeSummary *isp,
 
     memset(goodspecial, 0, sizeof(goodspecial));
 
-    skip = malloc(isp->nSpecialInodes * sizeof(*skip));
-    if (skip) {
-       memset(skip, 0, isp->nSpecialInodes * sizeof(*skip));
-    } else {
+    skip = calloc(isp->nSpecialInodes, sizeof(*skip));
+    if (skip == NULL) {
        Log("cannot allocate memory for inode skip array when salvaging "
            "volume %lu; not performing duplicate special inode recovery\n",
            afs_printable_uint32_lu(isp->volumeId));
index a293c58..c08c46d 100644 (file)
@@ -925,9 +925,8 @@ VInitVolumePackageThread(void *args)
             continue;
         }
         while ((vid = VInitNextVolumeId(dirp))) {
-            Volume *vp = (Volume*)malloc(sizeof(Volume));
+            Volume *vp = calloc(1, sizeof(Volume));
             osi_Assert(vp);
-            memset(vp, 0, sizeof(Volume));
             vp->device = partition->device;
             vp->partition = partition;
             vp->hashid = vid;
@@ -2215,9 +2214,8 @@ VPreAttachVolumeByVp_r(Error * ec,
        VOL_UNLOCK;
 
        /* allocate the volume structure */
-       vp = nvp = (Volume *) malloc(sizeof(Volume));
+       vp = nvp = calloc(1, sizeof(Volume));
        osi_Assert(vp != NULL);
-       memset(vp, 0, sizeof(Volume));
        queue_Init(&vp->vnode_list);
        queue_Init(&vp->rx_call_list);
        CV_INIT(&V_attachCV(vp), "vp attach", CV_DEFAULT, 0);
index be52de2..e062100 100644 (file)
@@ -1153,13 +1153,12 @@ ProcessIndex(Volume * vp, VnodeClass class, afs_foff_t ** Bufp, int *sizep,
            (size <=
             vcp->diskSize ? 0 : size - vcp->diskSize) >> vcp->logSize;
        if (nVnodes > 0) {
-           Buf = malloc(nVnodes * sizeof(afs_foff_t));
+           Buf = calloc(nVnodes,  sizeof(afs_foff_t));
            if (Buf == NULL) {
                STREAM_CLOSE(afile);
                FDH_CLOSE(fdP);
                return -1;
            }
-           memset(Buf, 0, nVnodes * sizeof(afs_foff_t));
            STREAM_ASEEK(afile, offset = vcp->diskSize);
            while (1) {
                code = STREAM_READ(vnode, vcp->diskSize, 1, afile);
index f1a8656..17e3805 100644 (file)
@@ -91,13 +91,11 @@ ExtractVnodes(struct Msg *m, Volume *vol, afs_int32 class,
        goto Bad_Extract;
     }
     size = FDH_SIZE(fdP);
-    *list = (struct VnodeExtract *) malloc(size / vcp->diskSize
-                                       * sizeof(struct VnodeExtract));
+    *list = calloc(size / vcp->diskSize, sizeof(struct VnodeExtract));
     if (!(*list)) {
        code = ENOMEM;
        goto Bad_Extract;
     }
-    memset(*list, 0, size / vcp->diskSize * sizeof(struct VnodeExtract));
     stream = FDH_FDOPEN(fdP, "r");
     if (!stream) {
        sprintf(m->line, "Couldn't stream open %s Index of volume %u\n",
@@ -712,8 +710,7 @@ split_volume(struct rx_call *call, Volume *vol, Volume *newvol,
     afs_uint32 parent;
     struct Msg *m;
 
-    m = (struct Msg *) malloc(sizeof(struct Msg));
-    memset(m, 0, sizeof(struct Msg));
+    m = calloc(1, sizeof(struct Msg));
     m->call = call;
     m->verbose = verbose;
 
index 8996fe0..71d89f7 100644 (file)
@@ -334,10 +334,9 @@ ViceCreateRoot(Volume *vp)
     afs_fsize_t length;
     ssize_t nBytes;
 
-    vnode = (struct VnodeDiskObject *)malloc(SIZEOF_LARGEDISKVNODE);
+    vnode = calloc(1, SIZEOF_LARGEDISKVNODE);
     if (!vnode)
        return ENOMEM;
-    memset(vnode, 0, SIZEOF_LARGEDISKVNODE);
 
     V_pref(vp, nearInode);
     inodeNumber =
@@ -2335,10 +2334,9 @@ VolListOneVolume(struct rx_call *acid, afs_int32 partid,
     int code;
     volint_info_handle_t handle;
 
-    volumeInfo->volEntries_val = (volintInfo *) malloc(sizeof(volintInfo));
+    volumeInfo->volEntries_val = calloc(1, sizeof(volintInfo));
     if (!volumeInfo->volEntries_val)
        return ENOMEM;
-    memset(volumeInfo->volEntries_val, 0, sizeof(volintInfo)); /* Clear structure */
 
     volumeInfo->volEntries_len = 1;
     if (GetPartName(partid, pname))
@@ -2440,11 +2438,9 @@ VolXListOneVolume(struct rx_call *a_rxCidP, afs_int32 a_partID,
      * Set up our pointers for action, marking our structure to hold exactly
      * one entry.  Also, assume we'll fail in our quest.
      */
-    a_volumeXInfoP->volXEntries_val =
-       (volintXInfo *) malloc(sizeof(volintXInfo));
+    a_volumeXInfoP->volXEntries_val = calloc(1, sizeof(volintXInfo));
     if (!a_volumeXInfoP->volXEntries_val)
        return ENOMEM;
-    memset(a_volumeXInfoP->volXEntries_val, 0, sizeof(volintXInfo)); /* Clear structure */
 
     a_volumeXInfoP->volXEntries_len = 1;
     code = ENODEV;
@@ -2549,11 +2545,9 @@ VolListVolumes(struct rx_call *acid, afs_int32 partid, afs_int32 flags,
     int code;
     volint_info_handle_t handle;
 
-    volumeInfo->volEntries_val =
-       (volintInfo *) malloc(allocSize * sizeof(volintInfo));
+    volumeInfo->volEntries_val = calloc(allocSize, sizeof(volintInfo));
     if (!volumeInfo->volEntries_val)
        return ENOMEM;
-    memset(volumeInfo->volEntries_val, 0, sizeof(volintInfo)); /* Clear structure */
 
     pntr = volumeInfo->volEntries_val;
     volumeInfo->volEntries_len = 0;
@@ -2679,11 +2673,9 @@ VolXListVolumes(struct rx_call *a_rxCidP, afs_int32 a_partID,
      * Allocate a large array of extended volume info structures, then
      * set it up for action.
      */
-    a_volumeXInfoP->volXEntries_val =
-       (volintXInfo *) malloc(allocSize * sizeof(volintXInfo));
+    a_volumeXInfoP->volXEntries_val = calloc(allocSize, sizeof(volintXInfo));
     if (!a_volumeXInfoP->volXEntries_val)
        return ENOMEM;
-    memset(a_volumeXInfoP->volXEntries_val, 0, sizeof(volintXInfo)); /* Clear structure */
 
     xInfoP = a_volumeXInfoP->volXEntries_val;
     a_volumeXInfoP->volXEntries_len = 0;
index 2e91f8c..6cd9361 100644 (file)
@@ -54,7 +54,7 @@ NewTrans(afs_uint32 avol, afs_int32 apart)
     struct volser_trans *tt, *newtt;
     struct timeval tp;
 
-    newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans));
+    newtt = calloc(1, sizeof(struct volser_trans));
     VTRANS_LOCK;
     /* don't allow the same volume to be attached twice */
     for (tt = allTrans; tt; tt = tt->next) {
@@ -65,7 +65,6 @@ NewTrans(afs_uint32 avol, afs_int32 apart)
        }
     }
     tt = newtt;
-    memset(tt, 0, sizeof(struct volser_trans));
     tt->volid = avol;
     tt->partition = apart;
     tt->refCount = 1;
index 801489c..bf59860 100644 (file)
@@ -3616,23 +3616,14 @@ UV_ReleaseVolume(afs_uint32 afromvol, afs_uint32 afromserver,
        nservers = entry.nServers; /* can do all, none offline */
     else
        nservers = entry.nServers / 2;
-    replicas =
-       (struct replica *)malloc(sizeof(struct replica) * nservers + 1);
-    times = (struct release *)malloc(sizeof(struct release) * nservers + 1);
-    toconns =
-       (struct rx_connection **)malloc(sizeof(struct rx_connection *) *
-                                       nservers + 1);
-    results.manyResults_val =
-       (afs_int32 *) malloc(sizeof(afs_int32) * nservers + 1);
+    replicas = calloc(nservers + 1, sizeof(struct replica));
+    times = calloc(nservers + 1, sizeof(struct release));
+    toconns = calloc(nservers + 1, sizeof(struct rx_connection *));
+    results.manyResults_val = calloc(nservers + 1, sizeof(afs_int32));
     if (!replicas || !times || !results.manyResults_val || !toconns)
        ONERROR0(ENOMEM,
                "Failed to create transaction on the release clone\n");
 
-    memset(replicas, 0, (sizeof(struct replica) * nservers + 1));
-    memset(times, 0, (sizeof(struct release) * nservers + 1));
-    memset(toconns, 0, (sizeof(struct rx_connection *) * nservers + 1));
-    memset(results.manyResults_val, 0, (sizeof(afs_int32) * nservers + 1));
-
     /* Create a transaction on the cloned volume */
     VPRINT1("Starting transaction on cloned volume %u...", cloneVolId);
     code =