Alfie Richards <alfie.richa...@arm.com> writes:

> Hi,
>
> Small fix to resolve an UBSAN diagnostic.
>
> Reg tested for Aarch64
>

To be sure: checked with bootstrap-ubsan too? (though note that it
doesn't error out by default, so you'd need to grep the logs or set
UBSAN_OPTIONS to make it error out)

> Thanks,
> Alfie
>
> -- >8 --
>
> This adds a nullptr check to fix a regression where it is possible to call
> `memcmp (NULL, NULL, 0)` which is UB.
>
> This should fix the bootstrap-ubsan build.

I can't approve but LGTM.

>
> gcc/ChangeLog:
>         PR middle-end/121261
>       * vec.h: Add null ptr check.
> ---
>  gcc/vec.h | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/gcc/vec.h b/gcc/vec.h
> index 9604edb1c3c..1277a881f1c 100644
> --- a/gcc/vec.h
> +++ b/gcc/vec.h
> @@ -2514,6 +2514,10 @@ public:
>        return false;
>      if (lhs.size () != rhs.size ())
>        return false;
> +    /* Case where either is a NULL pointer and therefore, as both are valid,
> +       both are empty slices with length 0.  */
> +    if (lhs.begin () == NULL || rhs.begin () == NULL)
> +      return true;
>      return memcmp (lhs.begin (), rhs.begin (), lhs.size ()) == 0;
>    }

Reply via email to