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 <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18522>
This commit is contained in:
vabr-g 2022-10-19 19:49:47 +00:00 committed by Marge Bot
parent cdbb30334c
commit 5bde671df2

View file

@ -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);
{