From: Simon Wilkinson Date: Thu, 17 May 2012 12:33:33 +0000 (+0100) Subject: Don't cast returns from malloc() X-Git-Tag: upstream/1.8.0_pre1^2~2369 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=519d2cd5d8bb2bc1d2e315b8fea9616504674c79;p=packages%2Fo%2Fopenafs.git Don't cast returns from malloc() malloc() returns a (void *) on all of our current platforms. So, don't bother casting the return value before assigning it - it is unnecessary noise. Change-Id: Ie328ebd2d31160bf07b86b760fbb5ce7108a532d Reviewed-on: http://gerrit.openafs.org/7473 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- diff --git a/src/afsd/afsd.c b/src/afsd/afsd.c index ac27729eb..a75e56cbf 100644 --- a/src/afsd/afsd.c +++ b/src/afsd/afsd.c @@ -1036,8 +1036,7 @@ doSweepAFSCache(int *vFilesFound, cache_dir_list[dirNum]++; /* keep directory's file count */ if (cache_dir_list[dirNum] > nFilesPerDir) { /* Too many files -- add to filelist */ - struct afsd_file_list *tmp = (struct afsd_file_list *) - malloc(sizeof(*tmp)); + struct afsd_file_list *tmp = malloc(sizeof(*tmp)); if (!tmp) printf ("%s: MALLOC FAILED allocating file_list entry\n", @@ -1371,7 +1370,7 @@ SweepAFSCache(int *vFilesFound) } if (cache_dir_list == NULL) { - cache_dir_list = (int *)malloc(maxDir * sizeof(*cache_dir_list)); + cache_dir_list = malloc(maxDir * sizeof(*cache_dir_list)); if (cache_dir_list == NULL) { printf("%s: Malloc Failed!\n", rn); return (-1); @@ -1389,7 +1388,7 @@ SweepAFSCache(int *vFilesFound) } if (dir_for_V == NULL) { - dir_for_V = (int *)malloc(cacheFiles * sizeof(*dir_for_V)); + dir_for_V = malloc(cacheFiles * sizeof(*dir_for_V)); if (dir_for_V == NULL) { printf("%s: Malloc Failed!\n", rn); return (-1); diff --git a/src/config/mc.c b/src/config/mc.c index 1233e57aa..97fc26ec4 100644 --- a/src/config/mc.c +++ b/src/config/mc.c @@ -63,7 +63,7 @@ ParseLine(char *aline, struct token **alist) return -1; /* should never get here */ else *tptr++ = 0; - ttok = (struct token *)malloc(sizeof(struct token)); + ttok = malloc(sizeof(struct token)); ttok->next = NULL; if (dontUse) { ttok->key = strdup(tbuffer + 1); /* Skip first char */ diff --git a/src/config/util_cr.c b/src/config/util_cr.c index 210c3e24d..45529dfb2 100644 --- a/src/config/util_cr.c +++ b/src/config/util_cr.c @@ -467,7 +467,7 @@ main(int argc, char *argv[]) if (file == NULL) usage(); len = filelength(_fileno(file)); - save = (char *)malloc(len + 1); + save = malloc(len + 1); buf = save; len = fread(buf, sizeof(char), len, file); buf[len] = 0; //set eof @@ -633,7 +633,7 @@ main(int argc, char *argv[]) if (file == NULL) exit(0xc000); len = filelength(_fileno(file)); - save = (char *)malloc(len + 2); + save = malloc(len + 2); ch = save; *ch++ = 0; /* a small hack to allow matching /r/n if /n is first character */ len = fread(ch, sizeof(char), len, file); @@ -655,7 +655,7 @@ main(int argc, char *argv[]) if (file == NULL) exit(0xc000); len = filelength(_fileno(file)); - save = (char *)malloc(len + 1); + save = malloc(len + 1); ch = save; len = fread(ch, sizeof(char), len, file); file = freopen(fname, "wb", file); @@ -674,7 +674,7 @@ main(int argc, char *argv[]) if (file == NULL) exit(0xc000); len = filelength(_fileno(file)); - save = (char *)malloc(len + 1); + save = malloc(len + 1); ch = save; len = fread(ch, sizeof(char), len, file); file = freopen(fname, "wb", file); @@ -684,7 +684,7 @@ main(int argc, char *argv[]) ch++; } fclose(file); - pvar = (char **)malloc(argc * sizeof(char *)); + pvar = malloc(argc * sizeof(char *)); for (i = 1; i < argc - 1; i++) pvar[i] = argv[i + 1]; pvar[argc - 1] = NULL; diff --git a/src/export/cfgexport.c b/src/export/cfgexport.c index 2eae23152..762b7ebe2 100644 --- a/src/export/cfgexport.c +++ b/src/export/cfgexport.c @@ -232,7 +232,7 @@ get_syms(conf, syms) if (debug) printf("nsyms = %d\n", nsyms); - x_symtab = (struct syment *)malloc(nsyms * SYMESZ); + x_symtab = malloc(nsyms * SYMESZ); if (!x_symtab) error("no memory for symbol table"); @@ -326,7 +326,7 @@ get_syms(conf, syms) /* * we will need no more than `nxsyms' symbols. */ - k_symtab = (sym_t *) malloc(nxsyms * sizeof(sym_t)); + k_symtab = malloc(nxsyms * sizeof(sym_t)); if (!k_symtab) error("no memory for EXPORT symbol table"); diff --git a/src/external/heimdal/roken/base64.c b/src/external/heimdal/roken/base64.c index 394e9841c..22c01e3b8 100644 --- a/src/external/heimdal/roken/base64.c +++ b/src/external/heimdal/roken/base64.c @@ -64,7 +64,7 @@ base64_encode(const void *data, int size, char **str) return -1; } - p = s = (char *) malloc(size * 4 / 3 + 4); + p = s = malloc(size * 4 / 3 + 4); if (p == NULL) { *str = NULL; return -1; diff --git a/src/fsprobe/fsprobe.c b/src/fsprobe/fsprobe.c index 0d62519cb..6f8cdbff5 100644 --- a/src/fsprobe/fsprobe.c +++ b/src/fsprobe/fsprobe.c @@ -231,8 +231,8 @@ fsprobe_LWP(void *unused) struct ProbeViceStatistics *curr_stats; /*Current stats region */ int *curr_probeOK; /*Current probeOK field */ ViceStatistics64 stats64; /*Current stats region */ - stats64.ViceStatistics64_val = (afs_uint64 *)malloc(STATS64_VERSION * - sizeof(afs_uint64)); + stats64.ViceStatistics64_val = malloc(STATS64_VERSION * + sizeof(afs_uint64)); while (1) { /*Service loop */ /* * Iterate through the server connections, gathering data. @@ -291,7 +291,7 @@ fsprobe_LWP(void *unused) char pname[10]; struct diskPartition partition; struct diskPartition64 *partition64p = - (struct diskPartition64 *)malloc(sizeof(struct diskPartition64)); + malloc(sizeof(struct diskPartition64)); if (fsprobe_debug) fprintf(stderr, @@ -573,7 +573,7 @@ fsprobe_Init(int a_numServers, struct sockaddr_in *a_socketArray, rn, fsprobe_statsBytes); fsprobe_probeOKBytes = a_numServers * sizeof(int); - fsprobe_Results.probeOK = (int *)malloc(fsprobe_probeOKBytes); + fsprobe_Results.probeOK = malloc(fsprobe_probeOKBytes); if (fsprobe_Results.probeOK == (int *)0) { fprintf(stderr, "[%s] Can't allocate %d probeOK array entries (%d bytes)\n", diff --git a/src/platform/SOLARIS/fs_conv_sol26.c b/src/platform/SOLARIS/fs_conv_sol26.c index 3bf52e805..b23acfe35 100644 --- a/src/platform/SOLARIS/fs_conv_sol26.c +++ b/src/platform/SOLARIS/fs_conv_sol26.c @@ -288,7 +288,7 @@ ProcessAfsInodes(devname, partition) goto out; } bufsize = super.fs.fs_ipg * sizeof(struct dinode); - if (!(inodes = (struct dinode *)malloc(bufsize))) { + if (!(inodes = malloc(bufsize))) { printf("Unable to allocate enough memory to scan inodes; help!\n"); goto out; } diff --git a/src/procmgmt/procmgmt_nt.c b/src/procmgmt/procmgmt_nt.c index e4fa7ef97..bc34bfb3c 100644 --- a/src/procmgmt/procmgmt_nt.c +++ b/src/procmgmt/procmgmt_nt.c @@ -546,7 +546,7 @@ StringArrayToString(char *strArray[]) } /* put all strings into buffer; guarantee buffer is at least one char */ - buffer = (char *)malloc(byteCount + (strCount * 3) /* quotes+space */ +1); + buffer = malloc(byteCount + (strCount * 3) /* quotes+space */ +1); if (buffer != NULL) { int i; @@ -585,7 +585,7 @@ StringArrayToMultiString(char *strArray[]) } /* put all strings into buffer; guarantee buffer is at least two chars */ - buffer = (char *)malloc(byteCount + strCount + 2); + buffer = malloc(byteCount + strCount + 2); if (buffer != NULL) { if (byteCount == 0) { buffer[0] = '\0'; @@ -764,7 +764,7 @@ ReadChildDataBuffer(void **datap, /* allocated data buffer */ size_t *memp = (size_t *) bufMemp; *dataLen = *memp++; - *datap = (void *)malloc(*dataLen); + *datap = malloc(*dataLen); if (*datap != NULL) { memcpy(*datap, (void *)memp, *dataLen); @@ -888,7 +888,7 @@ pmgt_ProcessSpawnVEB(const char *spath, char *sargv[], char *senvp[], } /* create path with .exe extension if no filename extension supplied */ - if (!(pathbuf = (char *)malloc(strlen(spath) + 5 /* .exe */ ))) { + if (!(pathbuf = malloc(strlen(spath) + 5 /* .exe */ ))) { errno = ENOMEM; return ((pid_t) - 1); } diff --git a/src/venus/fs.c b/src/venus/fs.c index 2249409a2..382d3cdfc 100644 --- a/src/venus/fs.c +++ b/src/venus/fs.c @@ -459,10 +459,10 @@ SetDotDefault(struct cmd_item **aitemp) if (*aitemp) return; /* already has value */ /* otherwise, allocate an item representing "." */ - ti = (struct cmd_item *)malloc(sizeof(struct cmd_item)); + ti = malloc(sizeof(struct cmd_item)); assert(ti); ti->next = (struct cmd_item *)0; - ti->data = (char *)malloc(2); + ti->data = malloc(2); assert(ti->data); strcpy(ti->data, "."); *aitemp = ti; @@ -499,7 +499,7 @@ ChangeList(struct Acl *al, afs_int32 plus, char *aname, afs_int32 arights, return; /* can't reduce non-existing rights */ /* Otherwise we make a new item and plug in the new data. */ - tlist = (struct AclEntry *)malloc(sizeof(struct AclEntry)); + tlist = malloc(sizeof(struct AclEntry)); assert(tlist); strcpy(tlist->name, aname); tlist->rights = arights; @@ -572,7 +572,7 @@ EmptyAcl(char *astr) struct Acl *tp; int junk; - tp = (struct Acl *)malloc(sizeof(struct Acl)); + tp = malloc(sizeof(struct Acl)); assert(tp); tp->nplus = tp->nminus = 0; tp->pluslist = tp->minuslist = 0; @@ -589,7 +589,7 @@ ParseAcl(char *astr) struct AclEntry *first, *last, *tl; struct Acl *ta; - ta = (struct Acl *)malloc(sizeof(struct Acl)); + ta = malloc(sizeof(struct Acl)); assert(ta); ta->dfs = 0; sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell); @@ -605,7 +605,7 @@ ParseAcl(char *astr) for (i = 0; i < nplus; i++) { sscanf(astr, "%100s %d", tname, &trights); astr = SkipLine(astr); - tl = (struct AclEntry *)malloc(sizeof(struct AclEntry)); + tl = malloc(sizeof(struct AclEntry)); assert(tl); if (!first) first = tl; @@ -623,7 +623,7 @@ ParseAcl(char *astr) for (i = 0; i < nminus; i++) { sscanf(astr, "%100s %d", tname, &trights); astr = SkipLine(astr); - tl = (struct AclEntry *)malloc(sizeof(struct AclEntry)); + tl = malloc(sizeof(struct AclEntry)); assert(tl); if (!first) first = tl; diff --git a/src/venus/fstrace.c b/src/venus/fstrace.c index b8ce877b4..2ed8e6ea3 100644 --- a/src/venus/fstrace.c +++ b/src/venus/fstrace.c @@ -699,7 +699,7 @@ icl_DumpKernel(FILE *outFilep, char *setname) if (bufferSize == 0) return -1; - bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize); + bufferp = malloc(sizeof(afs_int32) * bufferSize); if (!bufferp) return -1; @@ -985,7 +985,7 @@ icl_TailKernel(FILE *outFilep, char *logname, afs_int32 waitTime) if (bufferSize == 0) return -1; - bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize); + bufferp = malloc(sizeof(afs_int32) * bufferSize); if (!bufferp) { (void)fprintf(stderr, "cannot allocate %d words for buffer\n", bufferSize); @@ -1079,7 +1079,7 @@ icl_TailKernel(FILE *outFilep, char *logname, afs_int32 waitTime) /* have to reallocate a buffer */ bufferSize = newBufferSize; free(bufferp); - bufferp = (afs_int32 *) malloc(sizeof(afs_int32) * bufferSize); + bufferp = malloc(sizeof(afs_int32) * bufferSize); if (!bufferp) { (void)fprintf(stderr, "cannot allocate %d words for buffer\n", bufferSize); @@ -1210,17 +1210,17 @@ icl_CreateSetWithFlags(char *name, struct afs_icl_log *baseLogp, if (flags & ICL_CRSET_FLAG_PERSISTENT) states |= ICL_SETF_PERSISTENT; - setp = (struct afs_icl_set *)osi_Alloc(sizeof(struct afs_icl_set)); + setp = osi_Alloc(sizeof(struct afs_icl_set)); memset((caddr_t) setp, 0, sizeof(*setp)); setp->refCount = 1; if (states & ICL_SETF_FREED) states &= ~ICL_SETF_ACTIVE; /* if freed, can't be active */ setp->states = states; - setp->name = (char *)osi_Alloc(strlen(name) + 1); + setp->name = osi_Alloc(strlen(name) + 1); strcpy(setp->name, name); setp->nevents = ICL_DEFAULTEVENTS; - setp->eventFlags = (char *)osi_Alloc(ICL_DEFAULTEVENTS); + setp->eventFlags = osi_Alloc(ICL_DEFAULTEVENTS); for (i = 0; i < ICL_DEFAULTEVENTS; i++) setp->eventFlags[i] = 0xff; /* default to enabled */ @@ -1507,8 +1507,7 @@ icl_LogUse(struct afs_icl_log *logp) /* we weren't passed in a hint and it wasn't set */ logp->logSize = ICL_DEFAULT_LOGSIZE; } - logp->datap = - (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logp->logSize); + logp->datap = osi_Alloc(sizeof(afs_int32) * logp->logSize); } logp->setCount++; return 0; @@ -1542,7 +1541,7 @@ icl_LogSetSize(struct afs_icl_log *logp, afs_int32 logSize) /* free and allocate a new one */ osi_Free(logp->datap, sizeof(afs_int32) * logp->logSize); - logp->datap = (afs_int32 *) osi_Alloc(sizeof(afs_int32) * logSize); + logp->datap = osi_Alloc(sizeof(afs_int32) * logSize); logp->logSize = logSize; } diff --git a/src/venus/kdump.c b/src/venus/kdump.c index 185e39988..e70742fdd 100644 --- a/src/venus/kdump.c +++ b/src/venus/kdump.c @@ -667,7 +667,7 @@ read_ksyms(void) } availksyms = KSYM_ALLOC_BASE; - ksyms = (symlist_t *) malloc(availksyms * sizeof(symlist_t)); + ksyms = malloc(availksyms * sizeof(symlist_t)); if (!ksyms) { printf("Can't malloc %d elements for symbol list.\n", availksyms); exit(1); @@ -1345,9 +1345,8 @@ add_found_server(struct server *sep) if (NserversFound >= NserversAllocated) { NserversAllocated += SF_ALLOCATION_STEP; if (!serversFound) { - serversFound = - (struct server **)malloc(NserversAllocated * - sizeof(struct server *)); + serversFound = malloc(NserversAllocated * + sizeof(struct server *)); } else { serversFound = realloc(serversFound, NserversAllocated * @@ -1611,7 +1610,7 @@ print_dcaches(int pnt) kread(kmem, symoff, (char *)&count, sizeof count); findsym("afs_indexTable", &symoff); kread(kmem, symoff, (char *)&table, sizeof(long)); - ptr = (long *)malloc(count * sizeof(long)); + ptr = malloc(count * sizeof(long)); kread(kmem, table, (char *)ptr, count * sizeof(long)); for (i = 0, j = 0; i < count; i++) { if (dp = (struct dcache *)ptr[i]) { @@ -1650,7 +1649,7 @@ print_DindexTimes(int pnt) kread(kmem, symoff, (char *)&count, sizeof count); findsym("afs_indexTimes", &symoff); kread(kmem, symoff, (char *)&table, sizeof(long)); - ptr = (afs_hyper_t *) malloc(count * sizeof(afs_hyper_t)); + ptr = malloc(count * sizeof(afs_hyper_t)); kread(kmem, table, (char *)ptr, count * sizeof(afs_hyper_t)); for (i = 0, j = 0; i < count; i++) { if (pnt) @@ -1686,7 +1685,7 @@ print_DdvnextTbl(int pnt) kread(kmem, symoff, (char *)&count, sizeof count); findsym("afs_dvnextTbl", &symoff); kread(kmem, symoff, (char *)&table, sizeof(long)); - ptr = (afs_int32 *) malloc(count * sizeof(afs_int32)); + ptr = malloc(count * sizeof(afs_int32)); kread(kmem, table, (char *)ptr, count * sizeof(afs_int32)); for (i = 0, j = 0; i < count; i++) { if (pnt) @@ -1715,7 +1714,7 @@ print_DdcnextTbl(int pnt) kread(kmem, symoff, (char *)&count, sizeof count); findsym("afs_dcnextTbl", &symoff); kread(kmem, symoff, (char *)&table, sizeof(long)); - ptr = (afs_int32 *) malloc(count * sizeof(afs_int32)); + ptr = malloc(count * sizeof(afs_int32)); kread(kmem, table, (char *)ptr, count * sizeof(afs_int32)); for (i = 0, j = 0; i < count; i++) { if (pnt) @@ -1745,7 +1744,7 @@ print_DindexFlags(int pnt) kread(kmem, symoff, (char *)&count, sizeof count); findsym("afs_indexFlags", &symoff); kread(kmem, symoff, (char *)&table, sizeof(long)); - flags = (unsigned char *)malloc(count * sizeof(char)); + flags = malloc(count * sizeof(char)); kread(kmem, table, flags, count * sizeof(char)); for (i = 0, j = 0; i < count; i++) { if (pnt) @@ -1774,7 +1773,7 @@ print_buffers(int pnt) kread(kmem, symoff, (char *)&table, sizeof(long)); findsym("nbuffers", &symoff); kread(kmem, symoff, (char *)&count, sizeof(int)); - buffers = (unsigned char *)malloc(count * sizeof(struct buffer)); + buffers = malloc(count * sizeof(struct buffer)); kread(kmem, table, buffers, count * sizeof(struct buffer)); bp = (struct buffer *)buffers; for (i = 0, j = 0; i < count; i++, bp++) {