]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
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 bc105c5a2baccb9eed412e6fb60fed5c5f7a4aa2..ac27729eb2054fccca2ff2c826807c931df8188c 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 71410db0b9148ab4f183daad02407ec778d2ffcf..d074cbf7695e0e07e8116fabc9244b28f196b951 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 9d9d228376ab0ea1a6b82ff04bc5feb7d6604187..896dfd6bc371b6c2661ec1ef15d46cf0c119e21f 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 ba6843da104254bc3fba8289e781923b2b990c10..938c73114f7b813caa79ef4291ca0dde196c1143 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 82361534e7e4f9bd0778a3676fcb23ae18fe8c11..db5fd31b811c498ca98af8decebf262b7fb0faa5 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 0f67c3979d2011af8de469d14e37e2c1348cba11..9d99a1e68ba0e839e255425f21071767224fd26c 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 a79558cfdc1db12ae243c3b157a607b8678ea667..828f6ccd32812fd596a51f6cecf50028b9c27c74 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 334603308932e26004fd349cfbc75bf832366baf..4775f914d7235f1903d192b7fc41d41633bfdfc4 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 d5ceab0872363f791cc8f18a86f0d7995ca988a2..5c03fe30cbd7afb42a29062781045ad1fd0b3aa0 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 7e569a33396c0c2427b1df718175ab436fd61aa9..4c23e940632a3e3074a2b6119a96ecdf92702fd5 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 b1e1a2141b63b85dad2770841d51f6777ed15a1c..ecde75db0bcd8846c49a6a2f3f395643d824fe04 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 ea8b9c0400e990cba6a8942780174fbd54213b34..e702c401ce5ff7049bc91d76ccd9de6c3d3bee58 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 e184c49e9aa5342b34cd20caf32c7b6939cb6dd1..bcaf017a0fd17a223fa50b2d5ca385ed523ce659 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 08743a3cac56d5490baebc989441be6601eda401..74b17dbaffc11b8ffd2ac69a92806674709002a5 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 9af571322e5e2426b440581cde3a6d693a436114..ef11ec330bf1886f83caba4ac6f597e52da3c635 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 d6acc8c7960173cae85ccc9f85f37c9711ed829e..a0fb9ffd6eacabc407dd97e9c6472364bb06b699 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 3ca7cc0fb59edb05e3b8d2ba4dba9df5a5ac7bd4..a590dc5fecf02fbc5344f7e2418310f743970e8e 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 3fd3b4bcd33437a893a480e3b989280eda9d10cc..301d375ed149d21d421c3589a033d404122daf60 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 e4824c7b14b519bb5b3c3e027299da178732ed69..f2042f0938be1eaea98aaccf1432dba3ae0a1368 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 af7c6437cd0bb280f306844ef5739e14e0333b79..f9f9385c2d377c9ec7f9086f2e02e3e8bc2c8fbd 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 f6cdd353d04b7c532ce4328b461663d174957dee..6196cef3704c53d3b990b0e10b6de59922b025f7 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 ebc6b690f534a8be0a87fb79556dbe292c0fe5ee..92581216a50713e492616deb1fb6240cd2bb5596 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 5521ba55dc1626c7ecd4cacbaca2cccbeb9cd837..fac79aeb24b69558387735f70a752e6ecd53ed4f 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 0383ec850c5ab8ee75dde189d764e7abd9c76776..68f03e38c93a2da0be1fdef9c0be8a27d31232a6 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 c0828402bcd8c5102f5b598b9e0ef1e15416a241..fa9b1fd35d6a3774466f2e522f215ab309d4437e 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 3f51bab3626d1e1573db4efe43b9fc00fc78c992..d1f0f0a49f4b46cd18f3cb7e86c61c4fe5026f95 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 b755b5be3639979cb34fbf3f136ace0b35aea8af..4429c1c53f8bd7233cb7f304c1a9a0f92aff9989 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 66581365926616ed2a363b76cbd5ba36c184c058..9cca35c22485db8c3230adbcf98b7b3b11134969 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 857e153aa16bf17aa5156a645e25d1523ba61cec..3e746684e79e429f4a8dad21d6e55123c9df01bc 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",
@@ -172,11 +172,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);
index d52f572fdf23afafc51f746bcc23621aec2b5f26..cb5586302e7031e6b3fbcc49f2116280248bcdb8 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 e11cc0ac05cfd133ae21eeb48d3c81406a7aa03b..2db3f98690a63687f1cc8231319f89baa931af1a 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 0e5d247339affdf06e7f37275d600eacda33bc48..f9e7a45dd448373f67e1913eb4d5309817a73588 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 d6c1217537de5dcc0b99cfa7e66bb1d5d468df2e..ab983818ed2ca84847bd158e233713343b906618 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 780c6d9e5845be0ec6844eecf0c6a5614d8eb1c5..852a59fd42a0f155e25dffc9da1179262d98fe8f 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 abb82e8ddaf69d6d631a9bdf2e08a06cd257f41f..57e1107895a4280fd3f16b403e49e79e8c9c5820 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 72f2df33020dbc7130939eac609129384bd437b2..55421b29561b2337ed7c97cb9de8845a559adf7e 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 2ed325a6d8c4ab9b4437592af3b776a308901476..8f0a7bcc2da12c57094abd0d485b40ed75bdf699 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 0567851df3a4e4711cb3cce816e00aa57889f5fe..efc16a57b937e63e597943474a9a88ba9b087e70 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 6a04ab16cb3bf13a116f0d765105b30e027a7ebb..fde0252c4d688f2557e70bf9e27c8c4df15e266f 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 29114cdbc93f6e3a77ce6569293ee64697db8eac..d2770916346d200d984aff35d8f48e6e0ab464e0 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 cf8a68f4bff065d70404bacd67816391a4875c99..636ae5b908b4e0b9a242072086db445f44b636b7 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 bf5cbe69a03c87b5b9d447f7c06ee44734a7bd78..a8a8ef0b94c3aec525db3e001cd203aaf0c84117 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 f9a80a64c6f011692e359f3d130779c09e7adee3..75a8b267b59264d6e80ba26f70219061a7071f22 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 b65865d3149a4b6849185325c81f4aa5a7fe4138..8c50476bd10e32c3b742a4fa260904ce849c8ae5 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 c2f73af42c916ce0c46685e23445bb95183941e1..7654fc5fb6a2d81e12539c8a6d3dcf38c26f80bb 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 e1dffd1b1e134818e03b6d7c45de137434519025..2ce2ee0adb68913d28be6e55e1f4b75de6c4b85b 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 f9ffac29f3245f19f922524e2037267d67ecfc48..a3b9d3e0b7455896b11dd7ecc8c61590fb9013c3 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 1afdb8ed84be1ed86c391f14c2796f0ea630ffda..61f7a86253193db2873fcf4c027abe138dca2f02 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 d24c72f134b6fe95dbb1932072f920014138b746..c9266933ef0ee5afd90e41c775492832d9f7dc2e 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 527f89b1a79f5d0e789e97177a36c05952fa069d..eaad96fdb2d14a167e9e82e9b36efaf85ab3a08b 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 3367fd2909a40a5bbd564d50afa2fd32ac08fce2..b20f91fc1e1a2d185d76a96c58b7f9e81090d097 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 d12274d389c610cad352ef1b5b5c7ae831962a14..9fdcfc3ff306aba99f03e958f5e5531d9cdfe90e 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 17685eccd2d382cac5cdb37d487550f951849cab..ec8f479e03ac7e61cd4e7d04819c839402cccd8c 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 fb206615078ee70e92597a27c698b530cf99d14c..f66df08aceb69b6813e98a7df27267121a672baa 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 41786b508e336eeca37be431dd96e590b2524d11..28dfa54b2c1d0ea77f7ba5cf5a637b988b288ba2 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 7a18f0134f9d4cc5cb329844c367b0af11762449..ff093cdc7e9a20278b1b7d4660cc0757f282964e 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 3f35b693938c49e8f65d48a5f6c037dd9800dde5..421f3559595b81b60f5d99eca4c6de4adebbe8ae 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 11c560bd4322042af64dba793bd1282ebd551f5e..b8ce877b475a50af033ba28a9a292a94be29ac12 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 4aeae1aff524df9564a83ff9d81e609b4994e8c5..1ba3cda6be81f774066b33b98e3b205620219f74 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 f027e77972724e0fcb2acf29b7208aa4daf805db..005b1ec14067a3c5b426475de46328108ad3c63e 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 b0b426265dd486422261330c82cae559f5e8aaba..c8c2ed8039d83ee248afabd4058de02e1599f476 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 cd89a0d9a0a89bad81b69f3b9e98a9c7f62efa8b..dbd6930814700d17c7ead342fe171633e8cbbf3a 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 67f50d148e41c8fe1d4d373bca87bc276a1877aa..d9343bc8016a9ad78c1850ce8b8fb94fded7bf58 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 109b8e5a0f0e61abfc0136c94edf57a79e5da236..708bd3d7ac2099b404b6c7fa3a20b86cfff13b62 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 7146692fd64a430a53949f653b412d87be173302..0f189d99286043fb70647ba8e6e5d631a416866f 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 a293c58b059285038c49c8903aa832230bd02518..c08c46d08ff8e8327281d7b8a1864271b1ed44ee 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 be52de22cce74193b8a37fc90d329e6ce9ed4f6b..e062100365de7efa90563f5f0d437a0ea911f0d5 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 f1a8656bf309f90be3b7d768c16528b9cffd6017..17e3805138eff9cf97e552b6e099ff6be5c7ad5b 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 8996fe0ae63579dfa10a59ceac58d7465a90a352..71d89f7fc505f9e24425ba610179d9a44aecfca5 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 2e91f8cf0e7586deca4bce212fc2963199ee59a6..6cd9361e085f37c62a3103bc87c393a9ef975cbf 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 801489cb11b0311684299800d26dcbaa519f4038..bf59860229e7754b8145f61a660d63a5f5bd8d76 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 =