From b5c33174a125d5742e705b60249e06c3b83fac38 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Thu, 8 Apr 2021 18:46:02 -0400 Subject: [PATCH] dri: Use __DRI_BUFFER_COUNT consistently internally These arrays were all sized with insufficiently large magic numbers, which is probably not a good idea. Reviewed-By: Mike Blumenkrantz Part-of: --- src/gallium/frontends/dri/dri2.c | 5 ++++- src/gallium/frontends/dri/dri_drawable.h | 2 +- src/mesa/drivers/dri/i915/intel_context.c | 2 +- src/mesa/drivers/dri/i965/brw_context.c | 2 +- src/mesa/drivers/dri/nouveau/nouveau_context.c | 2 +- src/mesa/drivers/dri/radeon/radeon_common_context.c | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c index ee9945d03f2..781ddcb6c6f 100644 --- a/src/gallium/frontends/dri/dri2.c +++ b/src/gallium/frontends/dri/dri2.c @@ -107,10 +107,11 @@ dri2_drawable_get_buffers(struct dri_drawable *drawable, boolean with_format; __DRIbuffer *buffers; int num_buffers; - unsigned attachments[10]; + unsigned attachments[__DRI_BUFFER_COUNT]; unsigned num_attachments, i; assert(loader); + assert(*count <= __DRI_BUFFER_COUNT); with_format = dri_with_format(drawable->sPriv); num_attachments = 0; @@ -410,6 +411,8 @@ dri2_allocate_textures(struct dri_context *ctx, struct winsys_handle whandle; unsigned num_buffers = statts_count; + assert(num_buffers <= __DRI_BUFFER_COUNT); + /* First get the buffers from the loader */ if (image) { if (!dri_image_drawable_get_buffers(drawable, &images, diff --git a/src/gallium/frontends/dri/dri_drawable.h b/src/gallium/frontends/dri/dri_drawable.h index 71cc6070090..8514843464c 100644 --- a/src/gallium/frontends/dri/dri_drawable.h +++ b/src/gallium/frontends/dri/dri_drawable.h @@ -47,7 +47,7 @@ struct dri_drawable __DRIdrawable *dPriv; __DRIscreen *sPriv; - __DRIbuffer old[8]; + __DRIbuffer old[__DRI_BUFFER_COUNT]; unsigned old_num; unsigned old_w; unsigned old_h; diff --git a/src/mesa/drivers/dri/i915/intel_context.c b/src/mesa/drivers/dri/i915/intel_context.c index 7355e03edb2..4fe9f4b5609 100644 --- a/src/mesa/drivers/dri/i915/intel_context.c +++ b/src/mesa/drivers/dri/i915/intel_context.c @@ -683,7 +683,7 @@ intel_query_dri2_buffers(struct intel_context *intel, __DRIscreen *screen = intel->intelScreen->driScrnPriv; struct gl_framebuffer *fb = drawable->driverPrivate; int i = 0; - unsigned attachments[8]; + unsigned attachments[__DRI_BUFFER_COUNT]; struct intel_renderbuffer *front_rb; struct intel_renderbuffer *back_rb; diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c index 0a444a6431a..e80b03c00ce 100644 --- a/src/mesa/drivers/dri/i965/brw_context.c +++ b/src/mesa/drivers/dri/i965/brw_context.c @@ -1607,7 +1607,7 @@ brw_query_dri2_buffers(struct brw_context *brw, __DRIscreen *dri_screen = brw->screen->driScrnPriv; struct gl_framebuffer *fb = drawable->driverPrivate; int i = 0; - unsigned attachments[8]; + unsigned attachments[__DRI_BUFFER_COUNT]; struct brw_renderbuffer *front_rb; struct brw_renderbuffer *back_rb; diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c index c97fc0f23a5..014b3061e43 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_context.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c @@ -238,7 +238,7 @@ nouveau_update_renderbuffers(__DRIcontext *dri_ctx, __DRIdrawable *draw) __DRIscreen *screen = dri_ctx->driScreenPriv; struct gl_framebuffer *fb = draw->driverPrivate; struct nouveau_framebuffer *nfb = to_nouveau_framebuffer(fb); - unsigned int attachments[10]; + unsigned int attachments[__DRI_BUFFER_COUNT]; __DRIbuffer *buffers = NULL; int i = 0, count, ret; diff --git a/src/mesa/drivers/dri/radeon/radeon_common_context.c b/src/mesa/drivers/dri/radeon/radeon_common_context.c index becd30b8ce6..bd530af327a 100644 --- a/src/mesa/drivers/dri/radeon/radeon_common_context.c +++ b/src/mesa/drivers/dri/radeon/radeon_common_context.c @@ -361,7 +361,7 @@ void radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable, GLboolean front_only) { - unsigned int attachments[10]; + unsigned int attachments[__DRI_BUFFER_COUNT]; __DRIbuffer *buffers = NULL; __DRIscreen *screen; struct radeon_renderbuffer *rb;