From: Matthew Fernandez Date: Thu, 22 Oct 2020 00:03:54 +0000 (-0700) Subject: remove unnecessary casts of malloc() return value X-Git-Tag: 2.46.0~20^2^2~9^2~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e33fdf6d35f379bf53dc9656d07efba46077a617;p=graphviz remove unnecessary casts of malloc() return value malloc returns a void* which, in C, implicitly coerces to every other pointer type. --- diff --git a/cmd/smyrna/polytess.c b/cmd/smyrna/polytess.c index 2727045fa..73043503e 100644 --- a/cmd/smyrna/polytess.c +++ b/cmd/smyrna/polytess.c @@ -96,7 +96,7 @@ static void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4 { GLdouble *vertex; int i; - vertex = (GLdouble *) malloc(6 * sizeof(GLdouble)); + vertex = malloc(6 * sizeof(GLdouble)); vertex[0] = coords[0]; vertex[1] = coords[1]; vertex[2] = coords[2]; @@ -148,11 +148,11 @@ static int Render_Contour2(GLUtesselator *tobj,sdot_op* p) int x=0; /* int y=0; */ - d=(GLdouble**) malloc(sizeof(GLdouble)* p->op.u.polygon.cnt); + d= malloc(sizeof(GLdouble)* p->op.u.polygon.cnt); for (x=0;x < p->op.u.polygon.cnt; x++) { /* GLdouble temp; */ - d[x]=(GLdouble*)(malloc(sizeof(GLdouble)*3)); + d[x]=malloc(sizeof(GLdouble)*3); d[x][0]=p->op.u.polygon.pts[x].x; d[x][1]=p->op.u.polygon.pts[x].y; d[x][2]=p->op.u.polygon.pts[x].z+view->Topview->global_z; diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index 964c3bc15..bb50a1dc7 100644 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -749,7 +749,7 @@ int add_new_graph_to_viewport(void) { //returns graph index , otherwise -1 Agraph_t *graph; - graph = (Agraph_t *) malloc(sizeof(Agraph_t)); + graph = malloc(sizeof(Agraph_t)); if (graph) { view->graphCount = view->graphCount + 1; view->g[view->graphCount - 1] = graph; diff --git a/cmd/tools/bcomps.c b/cmd/tools/bcomps.c index 141b354af..584c57fc5 100644 --- a/cmd/tools/bcomps.c +++ b/cmd/tools/bcomps.c @@ -97,7 +97,7 @@ static char *blockName(char *gname, int d) if (sz > bufsz) { if (buf) free(buf); - buf = (char *) malloc(sz); + buf = malloc(sz); } if (*gname == '%') /* anonymous graph */ @@ -124,7 +124,7 @@ static char *getName(int ng, int nb) else { if (!buf) { sz = strlen(outfile) + 100; /* enough to handle '__' */ - buf = (char *) malloc(sz); + buf = malloc(sz); } if (suffix) { if (nb < 0) @@ -322,7 +322,7 @@ static void split(char *name) if (sfx) { size = sfx - name; suffix = sfx + 1; - path = (char *) malloc(size + 1); + path = malloc(size + 1); strncpy(path, name, size); *(path + size) = '\0'; } else { diff --git a/cmd/tools/ccomps.c b/cmd/tools/ccomps.c index 270df8d39..76e6c3a02 100644 --- a/cmd/tools/ccomps.c +++ b/cmd/tools/ccomps.c @@ -24,7 +24,7 @@ #include #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) typedef struct { Agrec_t h; @@ -113,7 +113,7 @@ static void split(char *name) if (sfx) { suffix = sfx + 1; size = sfx - name; - path = (char *) malloc(size + 1); + path = malloc(size + 1); strncpy(path, name, size); *(path + size) = '\0'; } else { @@ -353,7 +353,7 @@ static char *getName(void) name = outfile; else { if (!buf) - buf = (char *) malloc(strlen(outfile) + 20); /* enough to handle '_number' */ + buf = malloc(strlen(outfile) + 20); /* enough to handle '_number' */ if (suffix) sprintf(buf, "%s_%d.%s", path, sufcnt, suffix); else @@ -398,7 +398,7 @@ static char *getBuf(int n) if (n > len) { sz = n + 100; if (len == 0) - buf = (char *) malloc(sz); + buf = malloc(sz); else buf = (char *) realloc(buf, sz); len = sz; diff --git a/cmd/tools/gc.c b/cmd/tools/gc.c index 70e2bd78a..ce0c2de0d 100644 --- a/cmd/tools/gc.c +++ b/cmd/tools/gc.c @@ -24,7 +24,7 @@ #endif #include -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) #include diff --git a/cmd/tools/graphml2gv.c b/cmd/tools/graphml2gv.c index f30463f9d..447b9e4d3 100644 --- a/cmd/tools/graphml2gv.c +++ b/cmd/tools/graphml2gv.c @@ -55,7 +55,7 @@ struct slist { char buf[1]; }; -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) /* Round x up to next multiple of y, which is a power of 2 */ #define ROUND2(x,y) (((x) + ((y)-1)) & ~((y)-1)) diff --git a/cmd/tools/gv2gxl.c b/cmd/tools/gv2gxl.c index 78fac09f0..02bfbbba4 100644 --- a/cmd/tools/gv2gxl.c +++ b/cmd/tools/gv2gxl.c @@ -17,7 +17,7 @@ #define SMALLBUF 128 -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) #define EMPTY(s) ((s == 0) || (*s == '\0')) #define SLEN(s) (sizeof(s)-1) diff --git a/cmd/tools/gvcolor.c b/cmd/tools/gvcolor.c index 62c55507e..f3bea27fb 100644 --- a/cmd/tools/gvcolor.c +++ b/cmd/tools/gvcolor.c @@ -142,7 +142,7 @@ static void color(Agraph_t * g) /* assemble the sorted list of nodes and store the initial colors */ nn = agnnodes(g); - nlist = (Agnode_t **) malloc(nn * sizeof(Agnode_t *)); + nlist = malloc(nn * sizeof(Agnode_t *)); i = 0; for (n = agfstnode(g); n; n = agnxtnode(g, n)) { nlist[i++] = n; diff --git a/cmd/tools/gxl2gv.c b/cmd/tools/gxl2gv.c index 1cc11fecc..0ed306766 100644 --- a/cmd/tools/gxl2gv.c +++ b/cmd/tools/gxl2gv.c @@ -48,7 +48,7 @@ struct slist { char buf[1]; }; -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) /* Round x up to next multiple of y, which is a power of 2 */ #define ROUND2(x,y) (((x) + ((y)-1)) & ~((y)-1)) diff --git a/cmd/tools/matrix_market.c b/cmd/tools/matrix_market.c index 948b69c7a..1c37c6299 100644 --- a/cmd/tools/matrix_market.c +++ b/cmd/tools/matrix_market.c @@ -117,7 +117,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) type = mm_get_type(matcode); switch (type) { case MATRIX_TYPE_REAL: - val = (real *) malloc(nz * sizeof(real)); + val = malloc(nz * sizeof(real)); for (i = 0; i < nz; i++) { fscanf(f, "%d %d %lg\n", &I[i], &J[i], &val[i]); I[i]--; /* adjust from 1-based to 0-based */ @@ -153,7 +153,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) vp = (void *) val; break; case MATRIX_TYPE_INTEGER: - vali = (int *) malloc(nz * sizeof(int)); + vali = malloc(nz * sizeof(int)); for (i = 0; i < nz; i++) { fscanf(f, "%d %d %d\n", &I[i], &J[i], &vali[i]); I[i]--; /* adjust from 1-based to 0-based */ @@ -209,7 +209,7 @@ SparseMatrix SparseMatrix_import_matrix_market(FILE * f, int format) } break; case MATRIX_TYPE_COMPLEX: - val = (real *) malloc(2 * nz * sizeof(real)); + val = malloc(2 * nz * sizeof(real)); v = val; for (i = 0; i < nz; i++) { fscanf(f, "%d %d %lg %lg\n", &I[i], &J[i], &v[0], &v[1]); diff --git a/cmd/tools/mmio.c b/cmd/tools/mmio.c index 21bfebf27..2f23d8ecb 100644 --- a/cmd/tools/mmio.c +++ b/cmd/tools/mmio.c @@ -71,9 +71,9 @@ int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, /* reseve memory for matrices */ - I = (int *) malloc(nz * sizeof(int)); - J = (int *) malloc(nz * sizeof(int)); - val = (double *) malloc(nz * sizeof(double)); + I = malloc(nz * sizeof(int)); + J = malloc(nz * sizeof(int)); + val = malloc(nz * sizeof(double)); *val_ = val; *I_ = I; @@ -356,18 +356,18 @@ int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J, return ret_code; - *I = (int *) malloc(*nz * sizeof(int)); - *J = (int *) malloc(*nz * sizeof(int)); + *I = malloc(*nz * sizeof(int)); + *J = malloc(*nz * sizeof(int)); *val = NULL; if (mm_is_complex(*matcode)) { - *val = (double *) malloc(*nz * 2 * sizeof(double)); + *val = malloc(*nz * 2 * sizeof(double)); ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode); if (ret_code != 0) return ret_code; } else if (mm_is_real(*matcode)) { - *val = (double *) malloc(*nz * sizeof(double)); + *val = malloc(*nz * sizeof(double)); ret_code = mm_read_mtx_crd_data(f, *M, *N, *nz, *I, *J, *val, *matcode); if (ret_code != 0) diff --git a/cmd/tools/sccmap.c b/cmd/tools/sccmap.c index 2bd1f72d2..29ab835da 100644 --- a/cmd/tools/sccmap.c +++ b/cmd/tools/sccmap.c @@ -89,7 +89,7 @@ typedef struct { static void initStack(Stack * sp, int sz) { - sp->data = (Agnode_t **) malloc(sz * sizeof(Agnode_t *)); + sp->data = malloc(sz * sizeof(Agnode_t *)); sp->ptr = sp->data; } diff --git a/cmd/tools/tred.c b/cmd/tools/tred.c index 84b3e3086..3da9ab577 100644 --- a/cmd/tools/tred.c +++ b/cmd/tools/tred.c @@ -27,7 +27,7 @@ #include #include -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) typedef struct { @@ -289,7 +289,7 @@ static void process(Agraph_t * g, estack_t* sp) size_t infosize; infosize = (agnnodes(g)+1)*sizeof(nodeinfo_t); - ninfo = (nodeinfo_t*)malloc(infosize); + ninfo = malloc(infosize); if (Verbose) fprintf(stderr, "Processing graph %s\n", agnameof(g)); diff --git a/contrib/prune/generic_list.c b/contrib/prune/generic_list.c index 422caccbc..609cef784 100644 --- a/contrib/prune/generic_list.c +++ b/contrib/prune/generic_list.c @@ -25,13 +25,13 @@ generic_list_t *new_generic_list(uint64_t size) { generic_list_t *list; - list = (generic_list_t *) malloc(sizeof(generic_list_t)); + list = malloc(sizeof(generic_list_t)); if (list == NULL) { perror("[new_generic_list()] Error allocating memory:"); return NULL; } if (size != 0) { - list->data = (gl_data *) malloc(size * sizeof(gl_data)); + list->data = malloc(size * sizeof(gl_data)); if (list->data == NULL) { perror("[new_generic_list()] Error allocating memory:"); free(list); diff --git a/contrib/prune/prune.c b/contrib/prune/prune.c index fa6e1b11a..a244e2fdd 100644 --- a/contrib/prune/prune.c +++ b/contrib/prune/prune.c @@ -263,7 +263,7 @@ generic_list_t *addattr(generic_list_t * l, char *a) char *p; strattr_t *sp; - sp = (strattr_t *) malloc(sizeof(strattr_t)); + sp = malloc(sizeof(strattr_t)); if (sp == NULL) { perror("[addattr()->malloc()]"); exit(EXIT_FAILURE); diff --git a/doc/libgraph/sccmap.c b/doc/libgraph/sccmap.c index 8cd895726..e5334294b 100644 --- a/doc/libgraph/sccmap.c +++ b/doc/libgraph/sccmap.c @@ -49,7 +49,7 @@ typedef struct { static void initStack(Stack * sp, int sz) { - sp->data = (Agnode_t **) malloc(sz * sizeof(Agnode_t *)); + sp->data = malloc(sz * sizeof(Agnode_t *)); sp->ptr = sp->data; } diff --git a/lib/cdt/dtopen.c b/lib/cdt/dtopen.c index 0ea5f18b6..03d4aa620 100644 --- a/lib/cdt/dtopen.c +++ b/lib/cdt/dtopen.c @@ -15,7 +15,7 @@ Dt_t* dtopen(Dtdisc_t* disc, Dtmethod_t* meth) return NIL(Dt_t*); /* allocate space for dictionary */ - if(!(dt = (Dt_t*) malloc(sizeof(Dt_t)))) + if(!(dt = malloc(sizeof(Dt_t)))) return NIL(Dt_t*); /* initialize all absolutely private data */ diff --git a/lib/cdt/dtstat.c b/lib/cdt/dtstat.c index a5196ce20..8f25d6042 100644 --- a/lib/cdt/dtstat.c +++ b/lib/cdt/dtstat.c @@ -56,7 +56,7 @@ int dtstat(Dt_t* dt, Dtstat_t* ds, int all) if(ds->dt_max+1 > Size) { if(Size > 0) free(Count); - if(!(Count = (int*)malloc((ds->dt_max+1)*sizeof(int))) ) + if(!(Count = malloc((ds->dt_max+1)*sizeof(int))) ) return -1; Size = ds->dt_max+1; } @@ -70,7 +70,7 @@ int dtstat(Dt_t* dt, Dtstat_t* ds, int all) if(ds->dt_n+1 > Size) { if(Size > 0) free(Count); - if(!(Count = (int*)malloc((ds->dt_n+1)*sizeof(int))) ) + if(!(Count = malloc((ds->dt_n+1)*sizeof(int))) ) return -1; Size = ds->dt_n+1; } diff --git a/lib/cgraph/agerror.c b/lib/cgraph/agerror.c index 865e39198..0b4c2af05 100644 --- a/lib/cgraph/agerror.c +++ b/lib/cgraph/agerror.c @@ -49,7 +49,7 @@ char *aglasterr() fflush(agerrout); endpos = ftell(agerrout); len = endpos - aglast; - buf = (char*)malloc(len + 1); + buf = malloc(len + 1); fseek(agerrout, aglast, SEEK_SET); fread(buf, sizeof(char), len, agerrout); buf[len] = '\0'; @@ -70,7 +70,7 @@ userout (agerrlevel_t level, const char *fmt, va_list args) int n; if (!buf) { - buf = (char*)malloc(bufsz); + buf = malloc(bufsz); if (!buf) { fputs("userout: could not allocate memory\n", stderr ); return; diff --git a/lib/cgraph/refstr.c b/lib/cgraph/refstr.c index 8c52b4742..07d4d3bd0 100644 --- a/lib/cgraph/refstr.c +++ b/lib/cgraph/refstr.c @@ -107,7 +107,7 @@ char *agstrdup(Agraph_t * g, char *s) if (g) r = (refstr_t *) agalloc(g, sz); else - r = (refstr_t *) malloc(sz); + r = malloc(sz); r->refcnt = 1; strcpy(r->store, s); r->s = r->store; @@ -133,7 +133,7 @@ char *agstrdup_html(Agraph_t * g, char *s) if (g) r = (refstr_t *) agalloc(g, sz); else - r = (refstr_t *) malloc(sz); + r = malloc(sz); r->refcnt = 1 | HTML_BIT; strcpy(r->store, s); r->s = r->store; diff --git a/lib/common/routespl.c b/lib/common/routespl.c index b7d8ca660..8fe8c7cb7 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -906,10 +906,10 @@ typedef struct _tag_vec static vec* vec_new(void) { - vec* pvec = (vec*)malloc(sizeof(vec)); + vec* pvec = malloc(sizeof(vec)); pvec->_capelems = 10; pvec->_elems = 0; - pvec->_mem = (void**)malloc(pvec->_capelems * sizeof(void*)); + pvec->_mem = malloc(pvec->_capelems * sizeof(void*)); return pvec; } @@ -964,10 +964,10 @@ static boolean vec_contains(vec* pvec, void* item) static vec* vec_copy(vec* pvec) { - vec* nvec = (vec*)malloc(sizeof(vec)); + vec* nvec = malloc(sizeof(vec)); nvec->_capelems = pvec->_capelems; nvec->_elems = pvec->_elems; - nvec->_mem = (void**)malloc(pvec->_capelems * sizeof(void*)); + nvec->_mem = malloc(pvec->_capelems * sizeof(void*)); memcpy(nvec->_mem, pvec->_mem, pvec->_elems * sizeof(void*)); return nvec; } diff --git a/lib/glcomp/glcompfont.c b/lib/glcomp/glcompfont.c index 2ef74c3ad..91f7ca966 100644 --- a/lib/glcomp/glcompfont.c +++ b/lib/glcomp/glcompfont.c @@ -194,7 +194,7 @@ void glDeleteFont(glCompFont * f) glCompFont *glNewFont (glCompSet * s, char *text, glCompColor * c,glCompFontType type, char *fontdesc, int fs,int is2D) { - glCompFont *font = (glCompFont*) malloc(sizeof(glCompFont)); + glCompFont *font = malloc(sizeof(glCompFont)); font->reference = 0; font->color.R = c->R; font->color.G = c->G; diff --git a/lib/gvpr/actions.c b/lib/gvpr/actions.c index 82ba87578..7509b6e33 100644 --- a/lib/gvpr/actions.c +++ b/lib/gvpr/actions.c @@ -318,7 +318,7 @@ static void cloneGraph(Agraph_t * tgt, Agraph_t * src) Agraph_t *sg; char* name; Dt_t* emap = dtopen (&edgepair, Dtoset); - edgepair_t* data = (edgepair_t*)malloc(sizeof(edgepair_t)*agnedges(src)); + edgepair_t* data = malloc(sizeof(edgepair_t)*agnedges(src)); edgepair_t* ep = data; for (t = agfstnode(src); t; t = agnxtnode(src, t)) { diff --git a/lib/gvpr/mkdefs.c b/lib/gvpr/mkdefs.c index 0b1993f5b..91887bd08 100644 --- a/lib/gvpr/mkdefs.c +++ b/lib/gvpr/mkdefs.c @@ -70,7 +70,7 @@ static record *newRec(record * curr) { record *newr; - newr = (record *) malloc(sizeof(record)); + newr = malloc(sizeof(record)); if (!newr) { fprintf(stderr, "mkdefs: out of memory, line %d\n", lineno); exit(1); diff --git a/lib/ingraphs/ingraphs.c b/lib/ingraphs/ingraphs.c index bab9bc60b..dada29963 100644 --- a/lib/ingraphs/ingraphs.c +++ b/lib/ingraphs/ingraphs.c @@ -95,7 +95,7 @@ static ingraph_state* new_ing(ingraph_state * sp, char **files, Agraph_t** graphs, ingdisc * disc) { if (!sp) { - sp = (ingraph_state *) malloc(sizeof(ingraph_state)); + sp = malloc(sizeof(ingraph_state)); if (!sp) { fprintf(stderr, "ingraphs: out of memory\n"); return 0; @@ -114,7 +114,7 @@ new_ing(ingraph_state * sp, char **files, Agraph_t** graphs, ingdisc * disc) sp->ctr = 0; sp->errors = 0; sp->fp = NULL; - sp->fns = (ingdisc *) malloc(sizeof(ingdisc)); + sp->fns = malloc(sizeof(ingdisc)); if (!sp->fns) { fprintf(stderr, "ingraphs: out of memory\n"); if (sp->heap) diff --git a/lib/label/node.c b/lib/label/node.c index f9602c400..75f44551f 100644 --- a/lib/label/node.c +++ b/lib/label/node.c @@ -24,7 +24,7 @@ Node_t *RTreeNewNode(RTree_t * rtp) Node_t *n; rtp->NodeCount++; - n = (Node_t *) malloc(sizeof(Node_t)); + n = malloc(sizeof(Node_t)); InitNode(n); return n; } diff --git a/lib/neatogen/matrix_ops.c b/lib/neatogen/matrix_ops.c index 83f84e3bd..2c24178aa 100644 --- a/lib/neatogen/matrix_ops.c +++ b/lib/neatogen/matrix_ops.c @@ -154,8 +154,8 @@ mult_dense_mat(double **A, float **B, int dim1, int dim2, int dim3, storage = (float *) realloc(C[0], dim1 * dim3 * sizeof(A[0])); *CC = C = (float **) realloc(C, dim1 * sizeof(A)); } else { - storage = (float *) malloc(dim1 * dim3 * sizeof(A[0])); - *CC = C = (float **) malloc(dim1 * sizeof(A)); + storage = malloc(dim1 * dim3 * sizeof(A[0])); + *CC = C = malloc(dim1 * sizeof(A)); } for (i = 0; i < dim1; i++) { @@ -190,8 +190,8 @@ mult_dense_mat_d(double **A, float **B, int dim1, int dim2, int dim3, storage = (double *) realloc(C[0], dim1 * dim3 * sizeof(double)); *CC = C = (double **) realloc(C, dim1 * sizeof(double *)); } else { - storage = (double *) malloc(dim1 * dim3 * sizeof(double)); - *CC = C = (double **) malloc(dim1 * sizeof(double *)); + storage = malloc(dim1 * dim3 * sizeof(double)); + *CC = C = malloc(dim1 * sizeof(double *)); } for (i = 0; i < dim1; i++) { @@ -229,8 +229,8 @@ mult_sparse_dense_mat_transpose(vtx_data * A, double **B, int dim1, storage = (float *) realloc(C[0], dim1 * dim2 * sizeof(A[0])); *CC = C = (float **) realloc(C, dim1 * sizeof(A)); } else { - storage = (float *) malloc(dim1 * dim2 * sizeof(A[0])); - *CC = C = (float **) malloc(dim1 * sizeof(A)); + storage = malloc(dim1 * dim2 * sizeof(A[0])); + *CC = C = malloc(dim1 * sizeof(A)); } for (i = 0; i < dim1; i++) { diff --git a/lib/pathplan/route.c b/lib/pathplan/route.c index 9e0801221..699fd2d51 100644 --- a/lib/pathplan/route.c +++ b/lib/pathplan/route.c @@ -519,7 +519,7 @@ static void growops(int newopn) if (newopn <= opn) return; if (!ops) { - if (!(ops = (Ppoint_t *) malloc(POINTSIZE * newopn))) { + if (!(ops = malloc(POINTSIZE * newopn))) { prerror("cannot malloc ops"); longjmp(jbuf,1); } diff --git a/lib/pathplan/shortest.c b/lib/pathplan/shortest.c index 58428abc2..598db2657 100644 --- a/lib/pathplan/shortest.c +++ b/lib/pathplan/shortest.c @@ -513,11 +513,11 @@ static void growpnls(int newpnln) if (newpnln <= pnln) return; if (!pnls) { - if (!(pnls = (pointnlink_t *) malloc(POINTNLINKSIZE * newpnln))) { + if (!(pnls = malloc(POINTNLINKSIZE * newpnln))) { prerror("cannot malloc pnls"); longjmp(jbuf,1); } - if (!(pnlps = (pointnlink_t **) malloc(POINTNLINKPSIZE * newpnln))) { + if (!(pnlps = malloc(POINTNLINKPSIZE * newpnln))) { prerror("cannot malloc pnlps"); longjmp(jbuf,1); } @@ -542,7 +542,7 @@ static void growtris(int newtrin) if (newtrin <= trin) return; if (!tris) { - if (!(tris = (triangle_t *) malloc(TRIANGLESIZE * newtrin))) { + if (!(tris = malloc(TRIANGLESIZE * newtrin))) { prerror("cannot malloc tris"); longjmp(jbuf,1); } @@ -562,8 +562,7 @@ static void growdq(int newdqn) return; if (!dq.pnlps) { if (! - (dq.pnlps = - (pointnlink_t **) malloc(POINTNLINKPSIZE * newdqn))) { + (dq.pnlps = malloc(POINTNLINKPSIZE * newdqn))) { prerror("cannot malloc dq.pnls"); longjmp(jbuf,1); } @@ -583,7 +582,7 @@ static void growops(int newopn) if (newopn <= opn) return; if (!ops) { - if (!(ops = (Ppoint_t *) malloc(POINTSIZE * newopn))) { + if (!(ops = malloc(POINTSIZE * newopn))) { prerror("cannot malloc ops"); longjmp(jbuf,1); } diff --git a/lib/pathplan/shortestpth.c b/lib/pathplan/shortestpth.c index a79e660f3..9e071251b 100644 --- a/lib/pathplan/shortestpth.c +++ b/lib/pathplan/shortestpth.c @@ -37,8 +37,8 @@ static int *shortestPath(int root, int target, int V, array2 wadj) int k, t; /* allocate arrays */ - dad = (int *) malloc(V * sizeof(int)); - vl = (COORD *) malloc((V + 1) * sizeof(COORD)); /* One extra for sentinel */ + dad = malloc(V * sizeof(int)); + vl = malloc((V + 1) * sizeof(COORD)); /* One extra for sentinel */ val = vl + 1; /* initialize arrays */ @@ -99,7 +99,7 @@ int *makePath(Ppoint_t p, int pp, COORD * pvis, int V = conf->N; if (directVis(p, pp, q, qp, conf)) { - int *dad = (int *) malloc(sizeof(int) * (V + 2)); + int *dad = malloc(sizeof(int) * (V + 2)); dad[V] = V + 1; dad[V + 1] = -1; return dad; diff --git a/lib/pathplan/util.c b/lib/pathplan/util.c index 01844d47d..616f53b48 100644 --- a/lib/pathplan/util.c +++ b/lib/pathplan/util.c @@ -16,7 +16,7 @@ #include #include -#define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):(type*)malloc((size)*sizeof(type))) +#define ALLOC(size,ptr,type) (ptr? (type*)realloc(ptr,(size)*sizeof(type)):malloc((size)*sizeof(type))) Ppoly_t copypoly(Ppoly_t argpoly) { diff --git a/lib/pathplan/visibility.c b/lib/pathplan/visibility.c index 6549b333f..3a7ecdb91 100644 --- a/lib/pathplan/visibility.c +++ b/lib/pathplan/visibility.c @@ -34,7 +34,7 @@ static array2 allocArray(int V, int extra) array2 arr; COORD *p; - arr = (COORD **) malloc((V + extra) * sizeof(COORD *)); + arr = malloc((V + extra) * sizeof(COORD *)); p = (COORD *) calloc(V * V, sizeof(COORD)); for (i = 0; i < V; i++) { arr[i] = p; @@ -344,7 +344,7 @@ COORD *ptVis(vconfig_t * conf, int pp, Ppoint_t p) Ppoint_t pk; COORD d; - vadj = (COORD *) malloc((V + 2) * sizeof(COORD)); + vadj = malloc((V + 2) * sizeof(COORD)); if (pp == POLYID_UNKNOWN) diff --git a/lib/rbtree/test_red_black_tree.c b/lib/rbtree/test_red_black_tree.c index b8ac74057..60231fe87 100644 --- a/lib/rbtree/test_red_black_tree.c +++ b/lib/rbtree/test_red_black_tree.c @@ -60,7 +60,7 @@ int main() { { printf("type key for new node\n"); scanf("%i",&newKey); - newInt=(int*) malloc(sizeof(int)); + newInt= malloc(sizeof(int)); *newInt=newKey; RBTreeInsert(tree,newInt,0); } diff --git a/lib/sfio/sfcvt.c b/lib/sfio/sfcvt.c index d57da2f20..ed0357828 100644 --- a/lib/sfio/sfcvt.c +++ b/lib/sfio/sfcvt.c @@ -38,7 +38,7 @@ char *_sfcvt(void * dv, int n_digit, int *decpt, int *sign, int format) static char *Buf; /* set up local buffer */ - if (!Buf && !(Buf = (char *) malloc(SF_MAXDIGITS))) + if (!Buf && !(Buf = malloc(SF_MAXDIGITS))) return SF_INFINITE; *sign = *decpt = 0; diff --git a/lib/sfio/sfexcept.c b/lib/sfio/sfexcept.c index 860750638..69e6ea3f2 100644 --- a/lib/sfio/sfexcept.c +++ b/lib/sfio/sfexcept.c @@ -74,7 +74,7 @@ int _sfexcept(Sfio_t * f, int type, ssize_t io, Sfdisc_t * disc) if (f->size > 0) data = (uchar *) realloc((char *) f->data, size); else - data = (uchar *) malloc(size); + data = malloc(size); if (!data) goto chk_stack; f->endb = data + size; diff --git a/lib/sfio/sfexit.c b/lib/sfio/sfexit.c index de63d5b52..cb45ce1ac 100644 --- a/lib/sfio/sfexit.c +++ b/lib/sfio/sfexit.c @@ -68,7 +68,7 @@ waitpid(int pid, int *status, int options) return pid; } - if (!(w = (Waitpid_t *) malloc(sizeof(Waitpid_t)))) + if (!(w = malloc(sizeof(Waitpid_t)))) continue; w->pid = id; diff --git a/lib/sfio/sfmode.c b/lib/sfio/sfmode.c index b90c193f7..a582320ee 100644 --- a/lib/sfio/sfmode.c +++ b/lib/sfio/sfmode.c @@ -105,7 +105,7 @@ int _sfsetpool(Sfio_t * f) p->sf = p->array; } else { /* allocate a larger array */ n = (p->sf != p->array ? p->s_sf : (p->s_sf / 4 + 1) * 4) + 4; - if (!(array = (Sfio_t **) malloc(n * sizeof(Sfio_t *)))) + if (!(array = malloc(n * sizeof(Sfio_t *)))) goto done; /* move old array to new one */ @@ -137,7 +137,7 @@ Sfrsrv_t *_sfrsrv(Sfio_t * f, ssize_t size) /* make buffer if nothing yet */ size = ((size + SF_GRAIN - 1) / SF_GRAIN) * SF_GRAIN; if (!(rsrv = f->rsrv) || size > rsrv->size) { - if (!(rs = (Sfrsrv_t *) malloc(size + sizeof(Sfrsrv_t)))) + if (!(rs = malloc(size + sizeof(Sfrsrv_t)))) size = -1; else { if (rsrv) { @@ -177,7 +177,7 @@ int _sfpopen(Sfio_t * f, int fd, int pid, int stdio) if (f->proc) return 0; - if (!(p = f->proc = (Sfproc_t *) malloc(sizeof(Sfproc_t)))) + if (!(p = f->proc = malloc(sizeof(Sfproc_t)))) return -1; p->pid = pid; @@ -256,7 +256,7 @@ static int _sfpmode(Sfio_t * f, int type) if (p->ndata > p->size) { if (p->rdata) free((char *) p->rdata); - if ((p->rdata = (uchar *) malloc(p->ndata))) + if ((p->rdata = malloc(p->ndata))) p->size = p->ndata; else { p->size = 0; diff --git a/lib/sfio/sfnew.c b/lib/sfio/sfnew.c index 7bc8f4039..05171fa2a 100644 --- a/lib/sfio/sfnew.c +++ b/lib/sfio/sfnew.c @@ -75,7 +75,7 @@ Sfio_t *sfnew(Sfio_t * oldf, void * buf, size_t size, int file, } if (!f) { - if (!(f = (Sfio_t *) malloc(sizeof(Sfio_t)))) + if (!(f = malloc(sizeof(Sfio_t)))) return NIL(Sfio_t *); SFCLEAR(f); } diff --git a/lib/sfio/sfsetbuf.c b/lib/sfio/sfsetbuf.c index 183b5833a..a2db25021 100644 --- a/lib/sfio/sfsetbuf.c +++ b/lib/sfio/sfsetbuf.c @@ -236,7 +236,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) } if (!buf) { /* do allocation */ while (!buf && size > 0) { - if ((buf = (void *) malloc(size))) + if ((buf = malloc(size))) break; else size /= 2; diff --git a/lib/sfio/sfswap.c b/lib/sfio/sfswap.c index dbb083fd6..a607a5f04 100644 --- a/lib/sfio/sfswap.c +++ b/lib/sfio/sfswap.c @@ -48,7 +48,7 @@ Sfio_t *sfswap(Sfio_t * f1, Sfio_t * f2) f1->file == 1 ? sfstdout : f1->file == 2 ? sfstderr : NIL(Sfio_t *); if ((!f2 || !(f2->mode & SF_AVAIL))) { - if (!(f2 = (Sfio_t *) malloc(sizeof(Sfio_t)))) { + if (!(f2 = malloc(sizeof(Sfio_t)))) { f1->mode = f1mode; SFOPEN(f1, 0); return NIL(Sfio_t *); diff --git a/lib/sfio/sftable.c b/lib/sfio/sftable.c index 4e60141d4..f70c476c4 100644 --- a/lib/sfio/sftable.c +++ b/lib/sfio/sftable.c @@ -282,7 +282,7 @@ static Fmtpos_t *sffmtpos(Sfio_t * f, const char *form, va_list args, if (!fp) { /* constructing position array only */ if (!dollar - || !(fp = (Fmtpos_t *) malloc((maxp + 1) * sizeof(Fmtpos_t)))) + || !(fp = malloc((maxp + 1) * sizeof(Fmtpos_t)))) return NIL(Fmtpos_t *); for (n = 0; n <= maxp; ++n) fp[n].ft.fmt = 0; diff --git a/lib/sfio/sftmp.c b/lib/sfio/sftmp.c index 63ce5ff15..6ef7d3d03 100644 --- a/lib/sfio/sftmp.c +++ b/lib/sfio/sftmp.c @@ -30,9 +30,9 @@ char **_sfgetpath(char *path) while (*p && *p != ':') /* skip dir name */ ++p; } - if (n == 0 || !(dirs = (char **) malloc((n + 1) * sizeof(char *)))) + if (n == 0 || !(dirs = malloc((n + 1) * sizeof(char *)))) return NIL(char **); - if (!(p = (char *) malloc(strlen(path) + 1))) { + if (!(p = malloc(strlen(path) + 1))) { free(dirs); return NIL(char **); } diff --git a/lib/sfio/sfungetc.c b/lib/sfio/sfungetc.c index 5f0f68f6b..add8a1962 100644 --- a/lib/sfio/sfungetc.c +++ b/lib/sfio/sfungetc.c @@ -72,7 +72,7 @@ int sfungetc(Sfio_t * f, int c) uchar *data; if (f->size < 0) f->size = 0; - if (!(data = (uchar *) malloc(f->size + 16))) { + if (!(data = malloc(f->size + 16))) { c = -1; goto done; } diff --git a/lib/sfio/sfvprintf.c b/lib/sfio/sfvprintf.c index 3c34974c5..217ea7b53 100644 --- a/lib/sfio/sfvprintf.c +++ b/lib/sfio/sfvprintf.c @@ -461,7 +461,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) continue; fmstk->ft = ft = argv.ft; } else { /* stack a new environment */ - if (!(fm = (Fmt_t *) malloc(sizeof(Fmt_t)))) + if (!(fm = malloc(sizeof(Fmt_t)))) goto done; if (argv.ft->form) { diff --git a/lib/sfio/sfvscanf.c b/lib/sfio/sfvscanf.c index 2ba6b182d..7707d184c 100644 --- a/lib/sfio/sfvscanf.c +++ b/lib/sfio/sfvscanf.c @@ -439,7 +439,7 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) continue; fmstk->ft = ft = argv.ft; } else { /* stack a new environment */ - if (!(fm = (Fmt_t *) malloc(sizeof(Fmt_t)))) + if (!(fm = malloc(sizeof(Fmt_t)))) goto done; if (argv.ft->form) { diff --git a/plugin/core/gvrender_core_dot.c b/plugin/core/gvrender_core_dot.c index 3574ab23a..98a63174f 100644 --- a/plugin/core/gvrender_core_dot.c +++ b/plugin/core/gvrender_core_dot.c @@ -31,7 +31,7 @@ #include #include -#define GNEW(t) (t*)malloc(sizeof(t)) +#define GNEW(t) malloc(sizeof(t)) /* #define NEW_XDOT */ diff --git a/plugin/glitz/gvdevice_glitz.c b/plugin/glitz/gvdevice_glitz.c index b69423bff..8058b5cd3 100644 --- a/plugin/glitz/gvdevice_glitz.c +++ b/plugin/glitz/gvdevice_glitz.c @@ -278,7 +278,7 @@ static void init_window(GVJ_t *job, Display *dpy, int scr) char *name; window_t *window; - window = (window_t *)malloc(sizeof(window_t)); + window = malloc(sizeof(window_t)); if (window == NULL) { fprintf(stderr, "Failed to malloc window_t\n"); return; @@ -453,7 +453,7 @@ static void glitz_initialize(GVJ_t *firstjob) firstjob->display = (void*)dpy; firstjob->screen = scr; - keycodes = (KeyCode *)malloc(firstjob->numkeys * sizeof(KeyCode)); + keycodes = malloc(firstjob->numkeys * sizeof(KeyCode)); if (keycodes == NULL) { fprintf(stderr, "Failed to malloc %d*KeyCode\n", firstjob->numkeys); return; diff --git a/plugin/gs/gvloadimage_gs.c b/plugin/gs/gvloadimage_gs.c index 417087b15..e8c839979 100644 --- a/plugin/gs/gvloadimage_gs.c +++ b/plugin/gs/gvloadimage_gs.c @@ -181,7 +181,7 @@ static cairo_pattern_t* gvloadimage_gs_load(GVJ_t * job, usershape_t *us) } } if (!gs) { - gs = (gs_t *)malloc(sizeof(gs_t)); + gs = malloc(sizeof(gs_t)); if (!gs) { job->common->errorfn("malloc() failure\n"); return NULL; diff --git a/plugin/pango/gvgetfontlist_pango.c b/plugin/pango/gvgetfontlist_pango.c index 1f16e702a..ec99cf21e 100644 --- a/plugin/pango/gvgetfontlist_pango.c +++ b/plugin/pango/gvgetfontlist_pango.c @@ -245,7 +245,7 @@ typedef struct { int faces; } availfont_t; -#define NEW(t) (t*)malloc(sizeof(t)) +#define NEW(t) malloc(sizeof(t)) #define N_NEW(n,t) (t*)calloc((n),sizeof(t)) static PostscriptAlias postscript_alias[] = { diff --git a/plugin/xlib/gvdevice_xlib.c b/plugin/xlib/gvdevice_xlib.c index 55219b10d..3f1a9bf0c 100644 --- a/plugin/xlib/gvdevice_xlib.c +++ b/plugin/xlib/gvdevice_xlib.c @@ -272,7 +272,7 @@ static void init_window(GVJ_t *job, Display *dpy, int scr) int w, h; double zoom_to_fit; - window = (window_t *)malloc(sizeof(window_t)); + window = malloc(sizeof(window_t)); if (window == NULL) { fprintf(stderr, "Failed to malloc window_t\n"); return; @@ -473,7 +473,7 @@ static void xlib_initialize(GVJ_t *firstjob) firstjob->display = (void*)dpy; firstjob->screen = scr; - keycodes = (KeyCode *)malloc(firstjob->numkeys * sizeof(KeyCode)); + keycodes = malloc(firstjob->numkeys * sizeof(KeyCode)); if (keycodes == NULL) { fprintf(stderr, "Failed to malloc %d*KeyCode\n", firstjob->numkeys); return; diff --git a/tclpkg/tcldot/tcldot-id.c b/tclpkg/tcldot/tcldot-id.c index 096b2b318..fce9a7424 100644 --- a/tclpkg/tcldot/tcldot-id.c +++ b/tclpkg/tcldot/tcldot-id.c @@ -19,7 +19,7 @@ static void *myiddisc_open(Agraph_t *g, Agdisc_t *disc) { ictx_t *ictx = (ictx_t *)disc; gctx_t *gctx; - gctx = (gctx_t *)malloc(sizeof(gctx_t)); + gctx = malloc(sizeof(gctx_t)); gctx->g = g; gctx->ictx = ictx; return (void *)gctx; diff --git a/tclpkg/tclhandle/tclhandle.c b/tclpkg/tclhandle/tclhandle.c index 65eea83a8..f0faa01c7 100644 --- a/tclpkg/tclhandle/tclhandle.c +++ b/tclpkg/tclhandle/tclhandle.c @@ -101,7 +101,7 @@ static void tclhandleExpandTable(tblHeader_pt tblHdrPtr, int neededIdx) newSize = (tblHdrPtr->tableSize + numNewEntries) * tblHdrPtr->entrySize; - tblHdrPtr->bodyPtr = (ubyte_pt) malloc(newSize); + tblHdrPtr->bodyPtr = malloc(newSize); memcpy(tblHdrPtr->bodyPtr, oldbodyPtr, (tblHdrPtr->tableSize * tblHdrPtr->entrySize)); tclhandleLinkInNewEntries(tblHdrPtr, tblHdrPtr->tableSize, @@ -176,7 +176,7 @@ tblHeader_pt tclhandleInit(char *prefix, int entrySize, int initEntries) /* * Set up the table entry. */ - tblHdrPtr = (tblHeader_pt) malloc(sizeof(tblHeader_t)); + tblHdrPtr = malloc(sizeof(tblHeader_t)); /* * Calculate entry size, including header, rounded up to sizeof (void *). @@ -184,11 +184,10 @@ tblHeader_pt tclhandleInit(char *prefix, int entrySize, int initEntries) tblHdrPtr->entrySize = ENTRY_HEADER_SIZE + ROUND_ENTRY_SIZE(entrySize); tblHdrPtr->freeHeadIdx = NULL_IDX; tblHdrPtr->tableSize = initEntries; - tblHdrPtr->handleFormat = (char *) malloc(strlen(prefix) + 4); + tblHdrPtr->handleFormat = malloc(strlen(prefix) + 4); strcpy(tblHdrPtr->handleFormat, prefix); strcat(tblHdrPtr->handleFormat, "%lu"); - tblHdrPtr->bodyPtr = - (ubyte_pt) malloc(initEntries * tblHdrPtr->entrySize); + tblHdrPtr->bodyPtr = malloc(initEntries * tblHdrPtr->entrySize); tclhandleLinkInNewEntries(tblHdrPtr, 0, initEntries); return tblHdrPtr; @@ -249,8 +248,7 @@ int tclhandleReset(tblHeader_pt tblHdrPtr, int initEntries) free(tblHdrPtr->bodyPtr); tblHdrPtr->freeHeadIdx = NULL_IDX; tblHdrPtr->tableSize = initEntries; - tblHdrPtr->bodyPtr = - (ubyte_pt) malloc(initEntries * tblHdrPtr->entrySize); + tblHdrPtr->bodyPtr = malloc(initEntries * tblHdrPtr->entrySize); tclhandleLinkInNewEntries(tblHdrPtr, 0, initEntries); return TCL_OK; diff --git a/tclpkg/tclpathplan/find_ints.c b/tclpkg/tclpathplan/find_ints.c index e56628b60..1296c9524 100644 --- a/tclpkg/tclpathplan/find_ints.c +++ b/tclpkg/tclpathplan/find_ints.c @@ -34,8 +34,7 @@ void find_ints(struct vertex vertex_list[], all.first = all.final = NIL; all.number = 0; - pvertex = (struct vertex **) - malloc((input->nvertices) * sizeof(struct vertex *)); + pvertex = malloc((input->nvertices) * sizeof(struct vertex *)); for (i = 0; i < input->nvertices; i++) pvertex[i] = vertex_list + i; @@ -57,9 +56,7 @@ void find_ints(struct vertex vertex_list[], j++, tempa = tempa->next) find_intersection(tempa->name, templ, ilist, input); /* test */ - new = - (struct active_edge *) - malloc(sizeof(struct active_edge)); + new = malloc(sizeof(struct active_edge)); if (all.number == 0) { all.first = new; new->last = NIL; diff --git a/tclpkg/tclpathplan/tclpathplan.c b/tclpkg/tclpathplan/tclpathplan.c index 8caf37013..1e0cc20a0 100644 --- a/tclpkg/tclpathplan/tclpathplan.c +++ b/tclpkg/tclpathplan/tclpathplan.c @@ -889,7 +889,7 @@ vgpane(ClientData clientData, Tcl_Interp * interp, int argc, char *argv[]) char vbuf[30]; vgpane_t *vgp; - vgp = (vgpane_t *) malloc(sizeof(vgpane_t)); + vgp = malloc(sizeof(vgpane_t)); *(vgpane_t **) tclhandleAlloc(vgpaneTable, vbuf, NULL) = vgp; vgp->vc = (vconfig_t *) 0; diff --git a/tclpkg/tclpathplan/wrapper.c b/tclpkg/tclpathplan/wrapper.c index e72263516..295f97e48 100644 --- a/tclpkg/tclpathplan/wrapper.c +++ b/tclpkg/tclpathplan/wrapper.c @@ -41,8 +41,8 @@ int main(int argc, char **argv) { Ppoly_t polys[2], *polys_ptr[2]; - polys[0].ps = (Ppoint_t *) malloc(3 * sizeof(Ppoint_t)); - polys[1].ps = (Ppoint_t *) malloc(3 * sizeof(Ppoint_t)); + polys[0].ps = malloc(3 * sizeof(Ppoint_t)); + polys[1].ps = malloc(3 * sizeof(Ppoint_t)); polys[0].pn = 3; polys[1].pn = 3; @@ -101,14 +101,12 @@ int Plegal_arrangement(Ppoly_t ** polys, int n_polys) struct data input; struct intersection ilist[10000]; - polygon_list = (struct polygon *) - malloc(n_polys * sizeof(struct polygon)); + polygon_list = malloc(n_polys * sizeof(struct polygon)); for (i = nverts = 0; i < n_polys; i++) nverts += polys[i]->pn; - vertex_list = (struct vertex *) - malloc(nverts * sizeof(struct vertex)); + vertex_list = malloc(nverts * sizeof(struct vertex)); for (i = vno = 0; i < n_polys; i++) { polygon_list[i].start = &vertex_list[vno];