Don't cast the return value of malloc/realloc

This patch has been generated by the following Coccinelle semantic
patch:

// Don't cast the return value of malloc/realloc.
//
// Casting the return value of malloc/realloc only stands to hide
// errors.

@@
type T;
expression E1, E2;
@@
- (T)
(
_mesa_align_calloc(E1, E2)
|
_mesa_align_malloc(E1, E2)
|
calloc(E1, E2)
|
malloc(E1)
|
realloc(E1, E2)
)
This commit is contained in:
Matt Turner
2012-09-03 19:44:00 -07:00
parent 812931f602
commit 2b7a972e3f
93 changed files with 217 additions and 221 deletions
+5 -5
View File
@@ -201,7 +201,7 @@ XF86DRIOpenConnection(Display * dpy, int screen, drm_handle_t * hSAREA,
}
if (rep.length) {
if (!(*busIdString = (char *) calloc(rep.busIdStringLength + 1, 1))) {
if (!(*busIdString = calloc(rep.busIdStringLength + 1, 1))) {
_XEatData(dpy, ((rep.busIdStringLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
@@ -302,7 +302,7 @@ XF86DRIGetClientDriverName(Display * dpy, int screen,
if (rep.length) {
if (!
(*clientDriverName =
(char *) calloc(rep.clientDriverNameLength + 1, 1))) {
calloc(rep.clientDriverNameLength + 1, 1))) {
_XEatData(dpy, ((rep.clientDriverNameLength + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
@@ -521,7 +521,7 @@ XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
if (*numClipRects) {
int len = sizeof(drm_clip_rect_t) * (*numClipRects);
*pClipRects = (drm_clip_rect_t *) calloc(len, 1);
*pClipRects = calloc(len, 1);
if (*pClipRects)
_XRead(dpy, (char *) *pClipRects, len);
}
@@ -532,7 +532,7 @@ XF86DRIGetDrawableInfo(Display * dpy, int screen, Drawable drawable,
if (*numBackClipRects) {
int len = sizeof(drm_clip_rect_t) * (*numBackClipRects);
*pBackClipRects = (drm_clip_rect_t *) calloc(len, 1);
*pBackClipRects = calloc(len, 1);
if (*pBackClipRects)
_XRead(dpy, (char *) *pBackClipRects, len);
}
@@ -582,7 +582,7 @@ XF86DRIGetDeviceInfo(Display * dpy, int screen, drm_handle_t * hFrameBuffer,
*devPrivateSize = rep.devPrivateSize;
if (rep.length) {
if (!(*pDevPrivate = (void *) calloc(rep.devPrivateSize, 1))) {
if (!(*pDevPrivate = calloc(rep.devPrivateSize, 1))) {
_XEatData(dpy, ((rep.devPrivateSize + 3) & ~3));
UnlockDisplay(dpy);
SyncHandle();
+1 -1
View File
@@ -75,7 +75,7 @@ __indirect_glPushClientAttrib(GLuint mask)
if (spp < &gc->attributes.stack[__GL_CLIENT_ATTRIB_STACK_DEPTH]) {
if (!(sp = *spp)) {
sp = (__GLXattribute *) malloc(sizeof(__GLXattribute));
sp = malloc(sizeof(__GLXattribute));
*spp = sp;
}
sp->mask = mask;
+1 -1
View File
@@ -326,7 +326,7 @@ GetDrawableAttribute(Display * dpy, GLXDrawable drawable,
length = reply.length;
if (length) {
num_attributes = (use_glx_1_3) ? reply.numAttribs : length / 2;
data = (CARD32 *) malloc(length * sizeof(CARD32));
data = malloc(length * sizeof(CARD32));
if (data == NULL) {
/* Throw data on the floor */
_XEatData(dpy, length);
+1 -1
View File
@@ -146,7 +146,7 @@ __glXGetStringFromServer(Display * dpy, int opcode, CARD32 glxCode,
length = reply.length * 4;
numbytes = reply.size;
buf = (char *) malloc(numbytes);
buf = malloc(numbytes);
if (buf != NULL) {
_XRead(dpy, buf, numbytes);
length -= numbytes;
+1 -1
View File
@@ -2454,7 +2454,7 @@ _X_HIDDEN char *
__glXstrdup(const char *str)
{
char *copy;
copy = (char *) malloc(strlen(str) + 1);
copy = malloc(strlen(str) + 1);
if (!copy)
return NULL;
strcpy(copy, str);
+1 -1
View File
@@ -230,7 +230,7 @@ glx_config_create_list(unsigned count)
next = &base;
for (i = 0; i < count; i++) {
*next = (struct glx_config *) malloc(size);
*next = malloc(size);
if (*next == NULL) {
glx_config_destroy_list(base);
base = NULL;
+1 -1
View File
@@ -384,7 +384,7 @@ indirect_create_context(struct glx_screen *psc,
*/
bufSize = (XMaxRequestSize(psc->dpy) * 4) - sz_xGLXRenderReq;
gc->buf = (GLubyte *) malloc(bufSize);
gc->buf = malloc(bufSize);
if (!gc->buf) {
free(gc->client_state_private);
free(gc);
+4 -4
View File
@@ -89,7 +89,7 @@ __indirect_glMap1d(GLenum target, GLdouble u1, GLdouble u2, GLint stride,
if (stride != k) {
GLubyte *buf;
buf = (GLubyte *) malloc(compsize);
buf = malloc(compsize);
if (!buf) {
__glXSetError(gc, GL_OUT_OF_MEMORY);
return;
@@ -152,7 +152,7 @@ __indirect_glMap1f(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
if (stride != k) {
GLubyte *buf;
buf = (GLubyte *) malloc(compsize);
buf = malloc(compsize);
if (!buf) {
__glXSetError(gc, GL_OUT_OF_MEMORY);
return;
@@ -227,7 +227,7 @@ __indirect_glMap2d(GLenum target, GLdouble u1, GLdouble u2, GLint ustr,
if ((vstr != k) || (ustr != k * vord)) {
GLdouble *buf;
buf = (GLdouble *) malloc(compsize);
buf = malloc(compsize);
if (!buf) {
__glXSetError(gc, GL_OUT_OF_MEMORY);
return;
@@ -303,7 +303,7 @@ __indirect_glMap2f(GLenum target, GLfloat u1, GLfloat u2, GLint ustr,
if ((vstr != k) || (ustr != k * vord)) {
GLfloat *buf;
buf = (GLfloat *) malloc(compsize);
buf = malloc(compsize);
if (!buf) {
__glXSetError(gc, GL_OUT_OF_MEMORY);
return;
+2 -2
View File
@@ -84,7 +84,7 @@ __glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim,
GLubyte * pc, GLubyte * modes)
{
/* Allocate a temporary holding buffer */
GLubyte *buf = (GLubyte *) malloc(compsize);
GLubyte *buf = malloc(compsize);
if (!buf) {
__glXSetError(gc, GL_OUT_OF_MEMORY);
return;
@@ -178,7 +178,7 @@ __indirect_glSeparableFilter2D(GLenum target, GLenum internalformat,
pc += hdrlen;
/* Allocate a temporary holding buffer */
buf = (GLubyte *) malloc(bufsize);
buf = malloc(bufsize);
if (!buf) {
__glXSetError(gc, GL_OUT_OF_MEMORY);
return;
+3 -3
View File
@@ -68,7 +68,7 @@ __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
heightsize = __glImageSize(height, 1, 1, format, type, 0);
/* Allocate a holding buffer to transform the data from */
rowBuf = (GLubyte *) malloc(widthsize);
rowBuf = malloc(widthsize);
if (!rowBuf) {
/* Throw data away */
_XEatData(dpy, compsize);
@@ -82,7 +82,7 @@ __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
__glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row);
free((char *) rowBuf);
}
colBuf = (GLubyte *) malloc(heightsize);
colBuf = malloc(heightsize);
if (!colBuf) {
/* Throw data away */
_XEatData(dpy, compsize - __GLX_PAD(widthsize));
@@ -155,7 +155,7 @@ void gl_dispatch_stub_GetSeparableFilterEXT (GLenum target, GLenum format,
const GLint heightsize =
__glImageSize(height, 1, 1, format, type, 0);
GLubyte *const buf =
(GLubyte *) malloc((widthsize > heightsize) ? widthsize : heightsize);
malloc((widthsize > heightsize) ? widthsize : heightsize);
if (buf == NULL) {
/* Throw data away */
+1 -1
View File
@@ -245,7 +245,7 @@ DRI_glXUseXFont(struct glx_context *CC, Font font, int first, int count, int lis
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);
__glXSetError(CC, GL_OUT_OF_MEMORY);