https://gcc.gnu.org/g:c1102be3b25bde9989561b2610f8ee721a33a8e7
commit r16-2600-gc1102be3b25bde9989561b2610f8ee721a33a8e7 Author: Alfie Richards <alfie.richa...@arm.com> Date: Mon Jul 28 13:32:45 2025 +0000 Fix UB in string_slice::operator== (PR 121261) This adds a nullptr check to fix a regression where it is possible to call `memcmp (NULL, NULL, 0)` which is UB prior to C26. This fixes the bootstrap-ubsan build. gcc/ChangeLog: PR middle-end/121261 * vec.h: Add null ptr check. Diff: --- gcc/vec.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/vec.h b/gcc/vec.h index 9604edb1c3cf..0ea7a4957340 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.size () == 0) + return true; return memcmp (lhs.begin (), rhs.begin (), lhs.size ()) == 0; }