}
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) {
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));
/*
* 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)));
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;
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);
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) {
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);
{
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;
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;
}
/* 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);
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;
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;
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;
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);
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;
}
}
- 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;
}
}
- 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;
}
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;
}
/* 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;
}
/* 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);
*ss = 0;
return (BC_NOMEM);
}
- memset(*ps, 0, sizeof(struct partitionsort));
(*ps)->part = partition;
(*ps)->next = (*ss)->partitions;
(*ss)->partitions = *ps;
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)) {
}
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)) {
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) {
}
/* 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) {
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,
/* 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;
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],
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);
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;
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) {
/* 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);
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;
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);
/* 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;
}
/* 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) {
/* 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) {
* 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) {
}
/* 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;
{
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);
"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;
* 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 */
* 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);
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));
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)
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];
/* 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");
/* 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);
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);
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;
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++) {
* 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;
*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)
/* 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));
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 */
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);
/*
* 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);
}
* 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);
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 */
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",
* 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++)
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)) {
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;
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);
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;
}
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) {
}
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;
}
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));
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;
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;
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;
}
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;
}
}
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) {
#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) {
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;
{
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;
}
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));
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);
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;
* 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
* 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
//
// 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,
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;
{
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;
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;
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)
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) {
{
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;
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) {
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;
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 */
/* 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;
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;
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;
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;
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;
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;
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;
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;
}
}
- 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;
}
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();
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)
*/
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;
}
break;
}
- memset(tbuf, 0, sizeof(struct wbuf));
tbuf->buflen = BUFFLEN;
if (synthesize) {
afs_int64 ll, l = tbuf->buflen;
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);
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);
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;
}
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");
}
}
- memset(logInfo, 0, infoSize);
return logInfo;
}
}
/* 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))) {
}
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 */
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
* 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);
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;
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;
}
/**
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++;
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));
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;
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);
(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);
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",
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;
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 =
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))
* 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;
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;
* 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;
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) {
}
}
tt = newtt;
- memset(tt, 0, sizeof(struct volser_trans));
tt->volid = avol;
tt->partition = apart;
tt->refCount = 1;
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 =