v3d: do not access member of a NULL structure

Check if the structure is NULL before trying to get access to its
members.

This has been detected by the Undefined Behaviour Sanitizer (UBSan).

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Signed-off-by: Juan A. Suarez Romero <jasuarez@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29911>
This commit is contained in:
Juan A. Suarez Romero 2024-06-26 10:35:29 +02:00 committed by Marge Bot
parent fc286867fb
commit 417f70ef5a
2 changed files with 3 additions and 2 deletions

View file

@ -56,7 +56,8 @@ v3d_fence_reference(struct pipe_screen *pscreen,
struct v3d_fence *f = (struct v3d_fence *)pf;
struct v3d_fence *old = *p;
if (pipe_reference(&(*p)->reference, &f->reference)) {
if (pipe_reference(old ? &old->reference : NULL,
f ? &f->reference : NULL)) {
close(old->fd);
free(old);
}

View file

@ -1180,7 +1180,7 @@ v3d_resource_get_stencil(struct pipe_resource *prsc)
{
struct v3d_resource *rsc = v3d_resource(prsc);
return &rsc->separate_stencil->base;
return rsc->separate_stencil ? &rsc->separate_stencil->base : NULL;
}
static const struct u_transfer_vtbl transfer_vtbl = {