[Mesa-dev] [PATCH] mesa: silence coverity warning in _mesa_get_attachment()
Jose Fonseca
jfonseca at vmware.com
Thu Aug 16 10:51:04 PDT 2012
Given this sort of warning will pop-up all over the place, it would be nice to educate coverity without introducing any behaviour change or making logic statements unnecessarily more complex.
For example, I wonder if adding:
assert(ctx->Const.MaxColorAttachments <= Elements(fb->Attachment));
would be enough for coverity to realize this should never happen. This is more self-documenting -- our assumptions are clearly stated as such --, without changing behavior or making code more complex.
Jose
----- Original Message -----
> The warning is kind of bogus since the i >=
> ctx->Const.MaxColorAttachments
> will prevent out of bounds array accesses, but it's easily silenced.
>
> See http://bugs.freedesktop.org/show_bug.cgi?id=53426
> ---
> src/mesa/main/fbobject.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
> index aa8ba18..556426c 100644
> --- a/src/mesa/main/fbobject.c
> +++ b/src/mesa/main/fbobject.c
> @@ -215,8 +215,9 @@ _mesa_get_attachment(struct gl_context *ctx,
> struct gl_framebuffer *fb,
> * hardware is used.
> */
> i = attachment - GL_COLOR_ATTACHMENT0_EXT;
> - if (i >= ctx->Const.MaxColorAttachments
> - || (i > 0 && ctx->API == API_OPENGLES)) {
> + if (i >= ctx->Const.MaxColorAttachments ||
> + i >= Elements(fb->Attachment) ||
> + (i > 0 && ctx->API == API_OPENGLES)) {
> return NULL;
> }
> return &fb->Attachment[BUFFER_COLOR0 + i];
> --
> 1.7.3.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list