Don't cast the return value of malloc/realloc
authorMatt Turner <mattst88@gmail.com>
Mon, 22 Sep 2014 04:24:01 +0000 (21:24 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 9 Dec 2014 01:02:19 +0000 (17:02 -0800)
See commit 2b7a972e for the Coccinelle script.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/gallium/state_trackers/glx/xlib/glx_api.c
src/gallium/state_trackers/glx/xlib/glx_usefont.c
src/gallium/state_trackers/glx/xlib/xm_api.c
src/gallium/state_trackers/wgl/stw_tls.c
src/mesa/drivers/x11/fakeglx.c
src/mesa/drivers/x11/xm_api.c
src/mesa/main/imports.c
src/mesa/main/objectlabel.c
src/mesa/main/shaderapi.c
src/mesa/program/prog_instruction.c
src/mesa/program/prog_parameter.c

index 1807edbf5c2bcd03d90054350c4e665a87d71a1e..ad80dc09d1cf66f0cc29d2da4cb5d415066b2694 100644 (file)
@@ -253,8 +253,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
        */
       xmvis->vishandle = vinfo;
       /* Allocate more space for additional visual */
-      VisualTable = (XMesaVisual *) realloc( VisualTable,
-                                   sizeof(XMesaVisual) * (NumVisuals + 1));
+      VisualTable = realloc(VisualTable, sizeof(XMesaVisual) * (NumVisuals + 1));
       /* add xmvis to the list */
       VisualTable[NumVisuals] = xmvis;
       NumVisuals++;
@@ -1078,7 +1077,7 @@ glXChooseVisual( Display *dpy, int screen, int *list )
    xmvis = choose_visual(dpy, screen, list, GL_FALSE);
    if (xmvis) {
       /* create a new vishandle - the cached one may be stale */
-      xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo));
+      xmvis->vishandle = malloc(sizeof(XVisualInfo));
       if (xmvis->vishandle) {
          memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
       }
@@ -1829,8 +1828,7 @@ glXGetFBConfigs( Display *dpy, int screen, int *nelements )
    visTemplate.screen = screen;
    visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements);
    if (*nelements > 0) {
-      XMesaVisual *results;
-      results = (XMesaVisual *) malloc(*nelements * sizeof(XMesaVisual));
+      XMesaVisual *results = malloc(*nelements * sizeof(XMesaVisual));
       if (!results) {
          *nelements = 0;
          return NULL;
@@ -1864,7 +1862,7 @@ glXChooseFBConfig(Display *dpy, int screen,
 
    xmvis = choose_visual(dpy, screen, attribList, GL_TRUE);
    if (xmvis) {
-      GLXFBConfig *config = (GLXFBConfig *) malloc(sizeof(XMesaVisual));
+      GLXFBConfig *config = malloc(sizeof(XMesaVisual));
       if (!config) {
          *nitems = 0;
          return NULL;
@@ -1889,7 +1887,7 @@ glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config )
       return xmvis->vishandle;
 #else
       /* create a new vishandle - the cached one may be stale */
-      xmvis->vishandle = (XVisualInfo *) malloc(sizeof(XVisualInfo));
+      xmvis->vishandle = malloc(sizeof(XVisualInfo));
       if (xmvis->vishandle) {
          memcpy(xmvis->vishandle, xmvis->visinfo, sizeof(XVisualInfo));
       }
index de123f23f6faa59bb8c2e1d8cb266b429a11a89a..f7ee68b35659a22b9f2b6636ac5d0578afef880a 100644 (file)
@@ -241,7 +241,7 @@ glXUseXFont(Font font, int first, int count, int listbase)
    max_bm_width = (max_width + 7) / 8;
    max_bm_height = max_height;
 
-   bm = (GLubyte *) malloc((max_bm_width * max_bm_height) * sizeof(GLubyte));
+   bm = malloc((max_bm_width * max_bm_height) * sizeof(GLubyte));
    if (!bm) {
       XFreeFontInfo(NULL, fs, 1);
       _mesa_error(NULL, GL_OUT_OF_MEMORY,
index 2aa5ac4f86022d69733f424e5861075abe7c5a27..34be1f70108fc6ac7b9708e9bd8d4b40e7c0ca47 100644 (file)
@@ -705,7 +705,7 @@ XMesaVisual XMesaCreateVisual( Display *display,
     * the struct but we may need some of the information contained in it
     * at a later time.
     */
-   v->visinfo = (XVisualInfo *) malloc(sizeof(*visinfo));
+   v->visinfo = malloc(sizeof(*visinfo));
    if (!v->visinfo) {
       free(v);
       return NULL;
index 4b518452efc968a1cf67f1c51cac422443c3a7d8..ca27a53433ccb040d18926c9bcf327f2250ada63 100644 (file)
@@ -120,7 +120,7 @@ stw_tls_data_create(DWORD dwThreadId)
       debug_printf("%s(0x%04lx)\n", __FUNCTION__, dwThreadId);
    }
 
-   data = (struct stw_tls_data *)calloc(1, sizeof *data);
+   data = calloc(1, sizeof *data);
    if (!data) {
       goto no_data;
    }
index ee05f8aaa3d8d88e1dd58b9c385591d1bc3513ee..33c024a8c07b4a9d90def8af6a0b95065d3e9719 100644 (file)
@@ -326,8 +326,7 @@ save_glx_visual( Display *dpy, XVisualInfo *vinfo,
        */
       xmvis->vishandle = vinfo;
       /* Allocate more space for additional visual */
-      VisualTable = (XMesaVisual *) realloc( VisualTable,
-                                   sizeof(XMesaVisual) * (NumVisuals + 1));
+      VisualTable = realloc(VisualTable, sizeof(XMesaVisual) * (NumVisuals + 1));
       /* add xmvis to the list */
       VisualTable[NumVisuals] = xmvis;
       NumVisuals++;
index 2d66dbdcdf1626237f80985f16d15881d81393ae..b49133b730d9c2106241a3ddc902685050f6a564 100644 (file)
@@ -783,7 +783,7 @@ XMesaVisual XMesaCreateVisual( XMesaDisplay *display,
     * the struct but we may need some of the information contained in it
     * at a later time.
     */
-   v->visinfo = (XVisualInfo *) malloc(sizeof(*visinfo));
+   v->visinfo = malloc(sizeof(*visinfo));
    if(!v->visinfo) {
       free(v);
       return NULL;
index 4f5a2d11fa97d1e3c78c4d19aae07366b702f012..6945c2f621b1bbd930be29bb2458060d8ac5e1ed 100644 (file)
@@ -94,7 +94,7 @@ _mesa_align_malloc(size_t bytes, unsigned long alignment)
 
    ASSERT( alignment > 0 );
 
-   ptr = (uintptr_t)malloc(bytes + alignment + sizeof(void *));
+   ptr = malloc(bytes + alignment + sizeof(void *));
    if (!ptr)
       return NULL;
 
@@ -143,7 +143,7 @@ _mesa_align_calloc(size_t bytes, unsigned long alignment)
 
    ASSERT( alignment > 0 );
 
-   ptr = (uintptr_t)calloc(1, bytes + alignment + sizeof(void *));
+   ptr = calloc(1, bytes + alignment + sizeof(void *));
    if (!ptr)
       return NULL;
 
index efa7ba8d19a5e691cbcc81a9395b3b1db4b28f94..78df96b9ba84ce70784d20085913b6a1e0dfd515 100644 (file)
@@ -58,7 +58,7 @@ set_label(struct gl_context *ctx, char **labelPtr, const char *label,
                         MAX_LABEL_LENGTH);
 
          /* explicit length */
-         *labelPtr = (char *) malloc(length+1);
+         *labelPtr = malloc(length+1);
          if (*labelPtr) {
             memcpy(*labelPtr, label, length);
             /* length is not required to include the null terminator so
index 66578204f08053ce792527691f2b06180903076a..6d831f7621dc4f705e3bee8a45780639c65c6f9d 100644 (file)
@@ -274,9 +274,8 @@ attach_shader(struct gl_context *ctx, GLuint program, GLuint shader)
    }
 
    /* grow list */
-   shProg->Shaders = (struct gl_shader **)
-      realloc(shProg->Shaders,
-              (n + 1) * sizeof(struct gl_shader *));
+   shProg->Shaders = realloc(shProg->Shaders,
+                             (n + 1) * sizeof(struct gl_shader *));
    if (!shProg->Shaders) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "glAttachShader");
       return;
index 976024e3c7b8b8d7bcdda505a12d90c48964cb42..c1b952754f1e4b2cdfd7bd9d24b0307f09c0fefb 100644 (file)
@@ -87,13 +87,7 @@ struct prog_instruction *
 _mesa_realloc_instructions(struct prog_instruction *oldInst,
                            GLuint numOldInst, GLuint numNewInst)
 {
-   struct prog_instruction *newInst;
-
-   newInst = (struct prog_instruction *)
-      realloc(oldInst,
-              numNewInst * sizeof(struct prog_instruction));
-
-   return newInst;
+   return realloc(oldInst, numNewInst * sizeof(struct prog_instruction));
 }
 
 
index 896c6052b84f49648622d635e7f9e71f3e39d1cc..0ef46415d9f5fe5aa4e44c7514ec9e2abfcc908c 100644 (file)
@@ -120,7 +120,7 @@ _mesa_add_parameter(struct gl_program_parameter_list *paramList,
       paramList->Size = paramList->Size + 4 * sz4;
 
       /* realloc arrays */
-      paramList->Parameters = (struct gl_program_parameter *)
+      paramList->Parameters =
          realloc(paramList->Parameters,
                  paramList->Size * sizeof(struct gl_program_parameter));