From 8af4aaf351313f9d4692697bf28d3c3f84e01ca4 Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Sun, 21 Sep 2014 21:24:01 -0700 Subject: [PATCH] Don't cast the return value of malloc/realloc See commit 2b7a972e for the Coccinelle script. Reviewed-by: Brian Paul Reviewed-by: Ian Romanick --- src/gallium/state_trackers/glx/xlib/glx_api.c | 12 +++++------- src/gallium/state_trackers/glx/xlib/glx_usefont.c | 2 +- src/gallium/state_trackers/glx/xlib/xm_api.c | 2 +- src/gallium/state_trackers/wgl/stw_tls.c | 2 +- src/mesa/drivers/x11/fakeglx.c | 3 +-- src/mesa/drivers/x11/xm_api.c | 2 +- src/mesa/main/imports.c | 4 ++-- src/mesa/main/objectlabel.c | 2 +- src/mesa/main/shaderapi.c | 5 ++--- src/mesa/program/prog_instruction.c | 8 +------- src/mesa/program/prog_parameter.c | 2 +- 11 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/gallium/state_trackers/glx/xlib/glx_api.c b/src/gallium/state_trackers/glx/xlib/glx_api.c index 1807edb..ad80dc0 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_api.c +++ b/src/gallium/state_trackers/glx/xlib/glx_api.c @@ -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)); } diff --git a/src/gallium/state_trackers/glx/xlib/glx_usefont.c b/src/gallium/state_trackers/glx/xlib/glx_usefont.c index de123f2..f7ee68b 100644 --- a/src/gallium/state_trackers/glx/xlib/glx_usefont.c +++ b/src/gallium/state_trackers/glx/xlib/glx_usefont.c @@ -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, diff --git a/src/gallium/state_trackers/glx/xlib/xm_api.c b/src/gallium/state_trackers/glx/xlib/xm_api.c index 2aa5ac4..34be1f7 100644 --- a/src/gallium/state_trackers/glx/xlib/xm_api.c +++ b/src/gallium/state_trackers/glx/xlib/xm_api.c @@ -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; diff --git a/src/gallium/state_trackers/wgl/stw_tls.c b/src/gallium/state_trackers/wgl/stw_tls.c index 4b51845..ca27a53 100644 --- a/src/gallium/state_trackers/wgl/stw_tls.c +++ b/src/gallium/state_trackers/wgl/stw_tls.c @@ -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; } diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c index ee05f8a..33c024a 100644 --- a/src/mesa/drivers/x11/fakeglx.c +++ b/src/mesa/drivers/x11/fakeglx.c @@ -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++; diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c index 2d66dbd..b49133b 100644 --- a/src/mesa/drivers/x11/xm_api.c +++ b/src/mesa/drivers/x11/xm_api.c @@ -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; diff --git a/src/mesa/main/imports.c b/src/mesa/main/imports.c index 4f5a2d1..6945c2f 100644 --- a/src/mesa/main/imports.c +++ b/src/mesa/main/imports.c @@ -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; diff --git a/src/mesa/main/objectlabel.c b/src/mesa/main/objectlabel.c index efa7ba8..78df96b 100644 --- a/src/mesa/main/objectlabel.c +++ b/src/mesa/main/objectlabel.c @@ -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 diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c index 6657820..6d831f7 100644 --- a/src/mesa/main/shaderapi.c +++ b/src/mesa/main/shaderapi.c @@ -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; diff --git a/src/mesa/program/prog_instruction.c b/src/mesa/program/prog_instruction.c index 976024e..c1b9527 100644 --- a/src/mesa/program/prog_instruction.c +++ b/src/mesa/program/prog_instruction.c @@ -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)); } diff --git a/src/mesa/program/prog_parameter.c b/src/mesa/program/prog_parameter.c index 896c605..0ef4641 100644 --- a/src/mesa/program/prog_parameter.c +++ b/src/mesa/program/prog_parameter.c @@ -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)); -- 2.7.4