]> granicus.if.org Git - graphviz/commitdiff
remove unnecessary casts of realloc() return value
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 22 Oct 2020 00:04:33 +0000 (17:04 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 29 Oct 2020 00:13:11 +0000 (17:13 -0700)
realloc returns a void* which, in C, implicitly coerces to all other pointer
types

15 files changed:
cmd/smyrna/tvnodes.c
cmd/smyrna/viewport.c
cmd/tools/ccomps.c
contrib/prune/generic_list.c
lib/cgraph/agerror.c
lib/common/routespl.c
lib/neatogen/closest.c
lib/neatogen/dijkstra.c
lib/neatogen/matrix_ops.c
lib/pathplan/route.c
lib/pathplan/shortest.c
lib/pathplan/util.c
lib/sfio/sfexcept.c
lib/xdot/xdot.c
tclpkg/gv/gv_java_init.c

index cd94e7b16c9c6da4168be8fba0a58809bdc40101..5b2efc9c56ff146b0e4b8beeef47a132842fede1 100644 (file)
@@ -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;
index bb50a1dc7da8f1a0939c4fd39105fd9d7af1882a..378cc19acc3e22efbc719d192021665944a5b8d4 100644 (file)
@@ -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;
 
index 9ff360b7fbd9110a322a9b88958b25355a549e83..ffc90a6b73e29f0e72eef6431e58d1b27815da7b 100644 (file)
@@ -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;
index 609cef7846c528f2811216c9b09a9528639a146b..7d6826c7248ee3dff1d5eb99e5403d3da6c3942c 100644 (file)
@@ -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;
index 0b4c2af058d5378dcd62fd63870db946881bdce4..ff7c668ca5a2dca0b2f52c07479defd485af51ae 100644 (file)
@@ -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;
index 8fe8c7cb78488fbd7dd4f2097dc3f093737e8e3a..c4e9da9a6967ea0a8731ec4e8d6562579d947986 100644 (file)
@@ -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;  
 }
index b59f1ae585ff3316fb24f6e0aa554a5bbdc93e0d..89f8f40d4605a493d28cb0b83d4f3ad11b58ad3d 100644 (file)
@@ -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;
index f5c3c190964153d405d0e487977aa9e661d15fb4..e8fa818fbbe030439e55464ffa05449b5c3dcdbd 100644 (file)
@@ -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))! */
index 2c24178aa862f7cda67c0fc77a96f378911fe340..564e993ba9f169e5fed34b6c8809f3b15abccf46 100644 (file)
@@ -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));
index 699fd2d5132e0377b4afe2dec95d0d120b5b9ec3..14ddaccc0453a47ea134fc4686f992602d3066b1 100644 (file)
@@ -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);
        }
index 598db265735cb952b269cf6186dcfd9210f45cf0..63603b45f2a1346fdec7e8195ecc443a099c5327 100644 (file)
@@ -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);
        }
index 616f53b487345344c7ea95e27ed8238d49054188..589399f3966abc41ba51ab5c9f90fd32eebc7353 100644 (file)
@@ -16,7 +16,7 @@
 #include <stdlib.h>
 #include <pathplan/pathutil.h>
 
-#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)
 {
index 69e6ea3f2e1ec7ed76e8764bd8a8f226596cf9f4..cb4a8702bea8f74b8e49ebfff22ff9a74656c71d 100644 (file)
@@ -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)
index 6b908eb3eb99e1c9aced41b336dece57b9155cf2..43be4ac377829221a80cdbf78abb049a83ed3f4a 100644 (file)
@@ -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);
index a7f96cefb4f889b1f534cc94e7b2a49f990bef58..8550e625af347cc7ecb0900f5aa673fb425008ca 100644 (file)
@@ -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;