From: Alfie Richards Date: Mon, 28 Jul 2025 13:32:45 +0000 (+0000) Subject: Fix UB in string_slice::operator== (PR 121261) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c1102be3b25bde9989561b2610f8ee721a33a8e7;p=thirdparty%2Fgcc.git 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 --git a/gcc/vec.h b/gcc/vec.h index 9604edb1c3c..0ea7a495734 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; }