[Mesa-dev] [PATCH 3/6] meta: react to NULL pointers in create_texture_for_pbo()
Kenneth Graunke
kenneth at whitecape.org
Mon Jan 26 01:29:20 PST 2015
On Monday, January 26, 2015 11:07:48 AM Juha-Pekka Heikkila wrote:
> Check if null pointers were given and bail out.
>
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
> src/mesa/drivers/common/meta_tex_subimage.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/src/mesa/drivers/common/meta_tex_subimage.c b/src/mesa/drivers/common/meta_tex_subimage.c
> index 977ee5a..cd5218e 100644
> --- a/src/mesa/drivers/common/meta_tex_subimage.c
> +++ b/src/mesa/drivers/common/meta_tex_subimage.c
> @@ -82,6 +82,8 @@ create_texture_for_pbo(struct gl_context *ctx, bool create_pbo,
> assert(create_pbo);
>
> _mesa_GenBuffers(1, tmp_pbo);
> + if (!tmp_pbo)
> + return NULL;
>
> /* We are not doing this inside meta_begin/end. However, we know the
> * client doesn't have the given target bound, so we can go ahead and
> @@ -98,6 +100,11 @@ create_texture_for_pbo(struct gl_context *ctx, bool create_pbo,
> }
>
> _mesa_GenTextures(1, tmp_tex);
> + if (!tmp_tex) {
> + _mesa_DeleteBuffers(1, tmp_pbo);
> + return NULL;
> + }
> +
> tex_obj = _mesa_lookup_texture(ctx, *tmp_tex);
> tex_obj->Target = depth > 1 ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D;
> tex_obj->Immutable = GL_TRUE;
>
Unnecessary.
This is a static function, so all callers must be in the same source file.
Both callers pass the address of a local stack variable, which is clearly
not NULL. I'm surprised the static analysis tool wasn't smart enough to
figure this out - it's absolutely statically determinable.
You could potentially add
assert(tmp_pbo != NULL && tmp_tex != NULL);
to try and shut up the tool.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150126/67434d67/attachment.sig>
More information about the mesa-dev
mailing list