2023-10-11 Jakub Jelinek * wide-int.h (widest_int_storage ::write_val): If l is small and there is space in u.val array, store a canary value at the end when checking. (widest_int_storage ::set_len): Check the canary hasn't been overwritten. --- gcc/wide-int.h.jj 2023-10-11 12:05:47.718059477 +0200 +++ gcc/wide-int.h 2023-10-11 13:51:56.081552500 +0200 @@ -1635,6 +1635,8 @@ widest_int_storage ::write_val (unsig u.valp = XNEWVEC (HOST_WIDE_INT, l); return u.valp; } + else if (CHECKING_P && l < WIDE_INT_MAX_INL_ELTS) + u.val[l] = HOST_WIDE_INT_UC (0xbaaaaaaddeadbeef); return u.val; } @@ -1650,6 +1652,9 @@ widest_int_storage ::set_len (unsigne memcpy (u.val, valp, l * sizeof (u.val[0])); XDELETEVEC (valp); } + else if (len && len < WIDE_INT_MAX_INL_ELTS) + gcc_checking_assert ((unsigned HOST_WIDE_INT) u.val[len] + == HOST_WIDE_INT_UC (0xbaaaaaaddeadbeef)); len = l; /* There are no excess bits in val[len - 1]. */ STATIC_ASSERT (N % HOST_BITS_PER_WIDE_INT == 0);