Convert glamor & glx to new *allocarray functions

v2: fixup whitespace

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
This commit is contained in:
Alan Coopersmith 2015-03-21 15:05:30 -07:00
parent 7ac2802874
commit f59236c286
8 changed files with 19 additions and 21 deletions

View File

@ -57,7 +57,7 @@ _pixman_region_init_clipped_rectangles(pixman_region16_t * region,
unsigned int i, j;
if (num_rects > ARRAY_SIZE(stack_boxes)) {
boxes = malloc(sizeof(pixman_box16_t) * num_rects);
boxes = xallocarray(num_rects, sizeof(pixman_box16_t));
if (boxes == NULL)
return FALSE;
}

View File

@ -634,7 +634,7 @@ glyph_new_fixed_list(struct glamor_glyph_list *fixed_list,
}
DEBUGF("got %d lists\n", list_cnt);
if (list_cnt != 0) {
fixed_list->list = malloc(list_cnt * sizeof(*cur_list));
fixed_list->list = xallocarray(list_cnt, sizeof(*cur_list));
memcpy(fixed_list->list, *head_list, list_cnt * sizeof(*cur_list));
fixed_list->list[0].xOff = *head_x;
fixed_list->list[0].yOff = *head_y;

View File

@ -997,13 +997,13 @@ glamor_generate_radial_gradient_picture(ScreenPtr screen,
/* Set all the stops and colors to shader. */
if (stops_count > RADIAL_SMALL_STOPS) {
stop_colors = malloc(4 * stops_count * sizeof(float));
stop_colors = xallocarray(stops_count, 4 * sizeof(float));
if (stop_colors == NULL) {
ErrorF("Failed to allocate stop_colors memory.\n");
goto GRADIENT_FAIL;
}
n_stops = malloc(stops_count * sizeof(float));
n_stops = xallocarray(stops_count, sizeof(float));
if (n_stops == NULL) {
ErrorF("Failed to allocate n_stops memory.\n");
goto GRADIENT_FAIL;
@ -1338,13 +1338,13 @@ glamor_generate_linear_gradient_picture(ScreenPtr screen,
/* Set all the stops and colors to shader. */
if (stops_count > LINEAR_SMALL_STOPS) {
stop_colors = malloc(4 * stops_count * sizeof(float));
stop_colors = xallocarray(stops_count, 4 * sizeof(float));
if (stop_colors == NULL) {
ErrorF("Failed to allocate stop_colors memory.\n");
goto GRADIENT_FAIL;
}
n_stops = malloc(stops_count * sizeof(float));
n_stops = xallocarray(stops_count, sizeof(float));
if (n_stops == NULL) {
ErrorF("Failed to allocate n_stops memory.\n");
goto GRADIENT_FAIL;

View File

@ -775,7 +775,7 @@ _glamor_upload_bits_to_pixmap_texture(PixmapPtr pixmap, GLenum format,
if (pixmap->drawable.depth == 1)
stride = (((w * 8 + 7) / 8) + 3) & ~3;
converted_bits = malloc(h * stride);
converted_bits = xallocarray(h, stride);
if (converted_bits == NULL)
return FALSE;
@ -966,7 +966,7 @@ glamor_upload_sub_pixmap_to_texture(PixmapPtr pixmap, int x, int y, int w,
void *sub_bits;
int i, j;
sub_bits = malloc(h * stride);
sub_bits = xallocarray(h, stride);
if (sub_bits == NULL)
return FALSE;
box.x1 = x;

View File

@ -91,8 +91,8 @@ glamor_prep_pixmap_box(PixmapPtr pixmap, glamor_access_t access, BoxPtr box)
pixmap->devKind * pixmap->drawable.height, NULL,
gl_usage);
} else {
pixmap->devPrivate.ptr = malloc(pixmap->devKind *
pixmap->drawable.height);
pixmap->devPrivate.ptr = xallocarray(pixmap->devKind,
pixmap->drawable.height);
if (!pixmap->devPrivate.ptr)
return FALSE;
}

View File

@ -31,7 +31,7 @@ glamor_solid_boxes(PixmapPtr pixmap,
xRectangle *rect;
int n;
rect = malloc(nbox * sizeof (xRectangle));
rect = xallocarray(nbox, sizeof(xRectangle));
if (!rect)
return;
for (n = 0; n < nbox; n++) {

View File

@ -62,9 +62,8 @@ __glXDisp_FeedbackBuffer(__GLXclientState * cl, GLbyte * pc)
size = *(GLsizei *) (pc + 0);
type = *(GLenum *) (pc + 4);
if (cx->feedbackBufSize < size) {
cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf,
(size_t) size
* __GLX_SIZE_FLOAT32);
cx->feedbackBuf = reallocarray(cx->feedbackBuf,
(size_t) size, __GLX_SIZE_FLOAT32);
if (!cx->feedbackBuf) {
cl->client->errorValue = size;
return BadAlloc;
@ -94,8 +93,8 @@ __glXDisp_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
pc += __GLX_SINGLE_HDR_SIZE;
size = *(GLsizei *) (pc + 0);
if (cx->selectBufSize < size) {
cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
(size_t) size * __GLX_SIZE_CARD32);
cx->selectBuf = reallocarray(cx->selectBuf,
(size_t) size, __GLX_SIZE_CARD32);
if (!cx->selectBuf) {
cl->client->errorValue = size;
return BadAlloc;

View File

@ -63,9 +63,8 @@ __glXDispSwap_FeedbackBuffer(__GLXclientState * cl, GLbyte * pc)
size = *(GLsizei *) (pc + 0);
type = *(GLenum *) (pc + 4);
if (cx->feedbackBufSize < size) {
cx->feedbackBuf = (GLfloat *) realloc(cx->feedbackBuf,
(size_t) size
* __GLX_SIZE_FLOAT32);
cx->feedbackBuf = reallocarray(cx->feedbackBuf,
(size_t) size, __GLX_SIZE_FLOAT32);
if (!cx->feedbackBuf) {
cl->client->errorValue = size;
return BadAlloc;
@ -99,8 +98,8 @@ __glXDispSwap_SelectBuffer(__GLXclientState * cl, GLbyte * pc)
__GLX_SWAP_INT(pc + 0);
size = *(GLsizei *) (pc + 0);
if (cx->selectBufSize < size) {
cx->selectBuf = (GLuint *) realloc(cx->selectBuf,
(size_t) size * __GLX_SIZE_CARD32);
cx->selectBuf = reallocarray(cx->selectBuf,
(size_t) size, __GLX_SIZE_CARD32);
if (!cx->selectBuf) {
cl->client->errorValue = size;
return BadAlloc;