From: Matthew Fernandez Date: Thu, 22 Oct 2020 00:04:33 +0000 (-0700) Subject: remove unnecessary casts of realloc() return value X-Git-Tag: 2.46.0~20^2^2~9^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eceb49482f25cebe098f6db8465b3dc117622dd6;p=graphviz remove unnecessary casts of realloc() return value realloc returns a void* which, in C, implicitly coerces to all other pointer types --- diff --git a/cmd/smyrna/tvnodes.c b/cmd/smyrna/tvnodes.c index cd94e7b16..5b2efc9c5 100644 --- a/cmd/smyrna/tvnodes.c +++ b/cmd/smyrna/tvnodes.c @@ -324,8 +324,7 @@ static void add_column(grid * g, char *name, int editable, GType g_type) { if (*name == '\0') return; - g->columns = - (gridCol **) realloc(g->columns, + g->columns = realloc(g->columns, sizeof(gridCol *) * (g->count + 1)); g->columns[g->count] = NEW(gridCol); g->columns[g->count]->editable = editable; diff --git a/cmd/smyrna/viewport.c b/cmd/smyrna/viewport.c index bb50a1dc7..378cc19ac 100644 --- a/cmd/smyrna/viewport.c +++ b/cmd/smyrna/viewport.c @@ -719,8 +719,7 @@ int add_graph_to_viewport(Agraph_t * graph, char *id) { if (graph) { view->graphCount = view->graphCount + 1; - view->g = - (Agraph_t **) realloc(view->g, + view->g = realloc(view->g, sizeof(Agraph_t *) * view->graphCount); view->g[view->graphCount - 1] = graph; diff --git a/cmd/tools/ccomps.c b/cmd/tools/ccomps.c index 9ff360b7f..ffc90a6b7 100644 --- a/cmd/tools/ccomps.c +++ b/cmd/tools/ccomps.c @@ -400,7 +400,7 @@ static char *getBuf(int n) if (len == 0) buf = malloc(sz); else - buf = (char *) realloc(buf, sz); + buf = realloc(buf, sz); len = sz; } return buf; diff --git a/contrib/prune/generic_list.c b/contrib/prune/generic_list.c index 609cef784..7d6826c72 100644 --- a/contrib/prune/generic_list.c +++ b/contrib/prune/generic_list.c @@ -63,8 +63,7 @@ generic_list_t *add_to_generic_list(generic_list_t * list, gl_data element) } else { new_size = list->size * 2; } - new_data = - (gl_data *) realloc(list->data, new_size * sizeof(gl_data)); + new_data = realloc(list->data, new_size * sizeof(gl_data)); if (new_data == NULL) { perror("[add_to_generic_list()] Error allocating memory:"); return NULL; diff --git a/lib/cgraph/agerror.c b/lib/cgraph/agerror.c index 0b4c2af05..ff7c668ca 100644 --- a/lib/cgraph/agerror.c +++ b/lib/cgraph/agerror.c @@ -89,7 +89,7 @@ userout (agerrlevel_t level, const char *fmt, va_list args) break; } bufsz = MAX(bufsz*2,n+1); - if ((np = (char*)realloc(buf, bufsz)) == NULL) { + if ((np = realloc(buf, bufsz)) == NULL) { fputs("userout: could not allocate memory\n", stderr ); free(buf); return; diff --git a/lib/common/routespl.c b/lib/common/routespl.c index 8fe8c7cb7..c4e9da9a6 100644 --- a/lib/common/routespl.c +++ b/lib/common/routespl.c @@ -938,7 +938,7 @@ static void vec_push_back(vec* pvec, void* data) { if (pvec->_elems == pvec->_capelems) { pvec->_capelems += 10; - pvec->_mem = (void**)realloc(pvec->_mem, pvec->_capelems * sizeof(void*)); + pvec->_mem = realloc(pvec->_mem, pvec->_capelems * sizeof(void*)); } pvec->_mem[pvec->_elems++] = data; } diff --git a/lib/neatogen/closest.c b/lib/neatogen/closest.c index b59f1ae58..89f8f40d4 100644 --- a/lib/neatogen/closest.c +++ b/lib/neatogen/closest.c @@ -63,7 +63,7 @@ static void freeStack(PairStack * s) #define push(s,x) { \ if (s->top>=s->max_size) { \ s->max_size *= 2; \ - s->data = (Pair*) realloc(s->data, s->max_size*sizeof(Pair)); \ + s->data = realloc(s->data, s->max_size*sizeof(Pair)); \ } \ s->data[s->top++] = x; \ } @@ -132,7 +132,7 @@ static void initHeap(PairHeap * h, double *place, int *ordering, int n) #ifdef REDO if (h->heapSize > h->maxSize) { h->maxSize = h->heapSize; - h->data = (Pair *) realloc(h->data, h->maxSize * sizeof(Pair)); + h->data = realloc(h->data, h->maxSize * sizeof(Pair)); } #else h->maxSize = h->heapSize; @@ -167,7 +167,7 @@ static void insert(PairHeap * h, Pair edge) int i = h->heapSize; if (h->heapSize == h->maxSize) { h->maxSize *= 2; - h->data = (Pair *) realloc(h->data, h->maxSize * sizeof(Pair)); + h->data = realloc(h->data, h->maxSize * sizeof(Pair)); } h->heapSize++; h->data[i] = edge; diff --git a/lib/neatogen/dijkstra.c b/lib/neatogen/dijkstra.c index f5c3c1909..e8fa818fb 100644 --- a/lib/neatogen/dijkstra.c +++ b/lib/neatogen/dijkstra.c @@ -163,7 +163,7 @@ void dijkstra(int vertex, vtx_data * graph, int n, DistType * dist) #ifdef OBSOLETE mkHeap(&H, n); #endif - index = (int *) realloc(index, n * sizeof(int)); + index = realloc(index, n * sizeof(int)); /* initial distances with edge weights: */ for (i = 0; i < n; i++) @@ -223,8 +223,7 @@ dijkstra_bounded(int vertex, vtx_data * graph, int n, DistType * dist, num_visited_nodes = bfs_bounded(vertex, graph, n, dist, &Q, bound, visited_nodes); if (size < n) { - node_in_neighborhood = - (boolean *) realloc(node_in_neighborhood, n * sizeof(boolean)); + node_in_neighborhood = realloc(node_in_neighborhood, n * sizeof(boolean)); for (i = size; i < n; i++) { node_in_neighborhood[i] = FALSE; } @@ -238,7 +237,7 @@ dijkstra_bounded(int vertex, vtx_data * graph, int n, DistType * dist, #ifdef OBSOLETE mkHeap(&H, n); #endif - index = (int *) realloc(index, n * sizeof(int)); + index = realloc(index, n * sizeof(int)); /* initial distances with edge weights: */ for (i = 0; i < n; i++) /* far, TOO COSTLY (O(n))! */ diff --git a/lib/neatogen/matrix_ops.c b/lib/neatogen/matrix_ops.c index 2c24178aa..564e993ba 100644 --- a/lib/neatogen/matrix_ops.c +++ b/lib/neatogen/matrix_ops.c @@ -151,8 +151,8 @@ mult_dense_mat(double **A, float **B, int dim1, int dim2, int dim3, float *storage; float **C = *CC; if (C != NULL) { - storage = (float *) realloc(C[0], dim1 * dim3 * sizeof(A[0])); - *CC = C = (float **) realloc(C, dim1 * sizeof(A)); + storage = realloc(C[0], dim1 * dim3 * sizeof(A[0])); + *CC = C = realloc(C, dim1 * sizeof(A)); } else { storage = malloc(dim1 * dim3 * sizeof(A[0])); *CC = C = malloc(dim1 * sizeof(A)); @@ -187,8 +187,8 @@ mult_dense_mat_d(double **A, float **B, int dim1, int dim2, int dim3, double sum; if (C != NULL) { - storage = (double *) realloc(C[0], dim1 * dim3 * sizeof(double)); - *CC = C = (double **) realloc(C, dim1 * sizeof(double *)); + storage = realloc(C[0], dim1 * dim3 * sizeof(double)); + *CC = C = realloc(C, dim1 * sizeof(double *)); } else { storage = malloc(dim1 * dim3 * sizeof(double)); *CC = C = malloc(dim1 * sizeof(double *)); @@ -226,8 +226,8 @@ mult_sparse_dense_mat_transpose(vtx_data * A, double **B, int dim1, int nedges; float **C = *CC; if (C != NULL) { - storage = (float *) realloc(C[0], dim1 * dim2 * sizeof(A[0])); - *CC = C = (float **) realloc(C, dim1 * sizeof(A)); + storage = realloc(C[0], dim1 * dim2 * sizeof(A[0])); + *CC = C = realloc(C, dim1 * sizeof(A)); } else { storage = malloc(dim1 * dim2 * sizeof(A[0])); *CC = C = malloc(dim1 * sizeof(A)); diff --git a/lib/pathplan/route.c b/lib/pathplan/route.c index 699fd2d51..14ddaccc0 100644 --- a/lib/pathplan/route.c +++ b/lib/pathplan/route.c @@ -524,8 +524,7 @@ static void growops(int newopn) longjmp(jbuf,1); } } else { - if (!(ops = (Ppoint_t *) realloc((void *) ops, - POINTSIZE * newopn))) { + if (!(ops = realloc((void *) ops, POINTSIZE * newopn))) { prerror("cannot realloc ops"); longjmp(jbuf,1); } diff --git a/lib/pathplan/shortest.c b/lib/pathplan/shortest.c index 598db2657..63603b45f 100644 --- a/lib/pathplan/shortest.c +++ b/lib/pathplan/shortest.c @@ -522,14 +522,11 @@ static void growpnls(int newpnln) longjmp(jbuf,1); } } else { - if (!(pnls = (pointnlink_t *) realloc((void *) pnls, - POINTNLINKSIZE * newpnln))) { + if (!(pnls = realloc((void *) pnls, POINTNLINKSIZE * newpnln))) { prerror("cannot realloc pnls"); longjmp(jbuf,1); } - if (!(pnlps = (pointnlink_t **) realloc((void *) pnlps, - POINTNLINKPSIZE * - newpnln))) { + if (!(pnlps = realloc((void *) pnlps, POINTNLINKPSIZE * newpnln))) { prerror("cannot realloc pnlps"); longjmp(jbuf,1); } @@ -547,8 +544,7 @@ static void growtris(int newtrin) longjmp(jbuf,1); } } else { - if (!(tris = (triangle_t *) realloc((void *) tris, - TRIANGLESIZE * newtrin))) { + if (!(tris = realloc((void *) tris, TRIANGLESIZE * newtrin))) { prerror("cannot realloc tris"); longjmp(jbuf,1); } @@ -567,9 +563,7 @@ static void growdq(int newdqn) longjmp(jbuf,1); } } else { - if (!(dq.pnlps = (pointnlink_t **) realloc((void *) dq.pnlps, - POINTNLINKPSIZE * - newdqn))) { + if (!(dq.pnlps = realloc((void *) dq.pnlps, POINTNLINKPSIZE * newdqn))) { prerror("cannot realloc dq.pnls"); longjmp(jbuf,1); } @@ -587,8 +581,7 @@ static void growops(int newopn) longjmp(jbuf,1); } } else { - if (!(ops = (Ppoint_t *) realloc((void *) ops, - POINTSIZE * newopn))) { + if (!(ops = realloc((void *) ops, POINTSIZE * newopn))) { prerror("cannot realloc ops"); longjmp(jbuf,1); } diff --git a/lib/pathplan/util.c b/lib/pathplan/util.c index 616f53b48..589399f39 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)):malloc((size)*sizeof(type))) +#define ALLOC(size,ptr,type) (ptr? realloc(ptr,(size)*sizeof(type)):malloc((size)*sizeof(type))) Ppoly_t copypoly(Ppoly_t argpoly) { diff --git a/lib/sfio/sfexcept.c b/lib/sfio/sfexcept.c index 69e6ea3f2..cb4a8702b 100644 --- a/lib/sfio/sfexcept.c +++ b/lib/sfio/sfexcept.c @@ -72,7 +72,7 @@ int _sfexcept(Sfio_t * f, int type, ssize_t io, Sfdisc_t * disc) io = SF_GRAIN; size = ((size + io + SF_GRAIN - 1) / SF_GRAIN) * SF_GRAIN; if (f->size > 0) - data = (uchar *) realloc((char *) f->data, size); + data = realloc((char *) f->data, size); else data = malloc(size); if (!data) diff --git a/lib/xdot/xdot.c b/lib/xdot/xdot.c index 6b908eb3e..43be4ac37 100644 --- a/lib/xdot/xdot.c +++ b/lib/xdot/xdot.c @@ -435,7 +435,7 @@ xdot *parseXDotFOn (char *s, drawfunc_t fns[], int sz, xdot* x) else { ops = (char*)(x->ops); bufsz = initcnt + XDBSIZE; - ops = (char *) realloc(ops, bufsz * sz); + ops = realloc(ops, bufsz * sz); memset(ops + (initcnt*sz), '\0', (bufsz - initcnt)*sz); } @@ -443,7 +443,7 @@ xdot *parseXDotFOn (char *s, drawfunc_t fns[], int sz, xdot* x) if (x->cnt == bufsz) { oldsz = bufsz; bufsz *= 2; - ops = (char *) realloc(ops, bufsz * sz); + ops = realloc(ops, bufsz * sz); memset(ops + (oldsz*sz), '\0', (bufsz - oldsz)*sz); } *(xdot_op *) (ops + (x->cnt * sz)) = op; @@ -452,7 +452,7 @@ xdot *parseXDotFOn (char *s, drawfunc_t fns[], int sz, xdot* x) if (error) x->flags |= XDOT_PARSE_ERROR; if (x->cnt) { - x->ops = (xdot_op *) realloc(ops, x->cnt * sz); + x->ops = realloc(ops, x->cnt * sz); } else { free (ops); diff --git a/tclpkg/gv/gv_java_init.c b/tclpkg/gv/gv_java_init.c index a7f96cefb..8550e625a 100644 --- a/tclpkg/gv/gv_java_init.c +++ b/tclpkg/gv/gv_java_init.c @@ -33,7 +33,7 @@ static size_t gv_string_writer(GVJ_t *job, const char *s, size_t len) bap->sz *= 2; if (newlen > bap->sz) bap->sz = 2*newlen; - bap->data = (char*)realloc(bap->data, bap->sz); + bap->data = realloc(bap->data, bap->sz); } memcpy (bap->data+bap->len, s, len); bap->len = newlen;