From 5bde671df240879da0cdab062c02a0f0bcd459ca Mon Sep 17 00:00:00 2001 From: vabr-g Date: Wed, 19 Oct 2022 19:49:47 +0000 Subject: [PATCH] gallium: Avoid nullptr-with-nonzero-offset reserve() in rtasm_x86sse compares a pointer difference with some integers to check if reallocation is needed. It unfortunately groups the first pointer with an int, which makes it possible to hit nullptr-with-nonzero-offset under Undefined Behavior Sanitizer. This patch suggests a reordering of the arithmetic expression so that first the pointer difference is computed, and from that on it's just a usual integer arithmetic, avoiding nullptr-with-nonzero-offset. Reviewed-by: Emma Anholt Part-of: --- src/gallium/auxiliary/rtasm/rtasm_x86sse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c index 9fc3a712244..1a5678f8407 100644 --- a/src/gallium/auxiliary/rtasm/rtasm_x86sse.c +++ b/src/gallium/auxiliary/rtasm/rtasm_x86sse.c @@ -174,7 +174,7 @@ static void do_realloc( struct x86_function *p ) */ static unsigned char *reserve( struct x86_function *p, int bytes ) { - if (p->csr + bytes - p->store > (int) p->size) + if (p->csr - p->store + bytes > (int) p->size) do_realloc(p); {