https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116936
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:f82055f8247478d9e2c00f2a442248e42188b8d1 commit r15-4064-gf82055f8247478d9e2c00f2a442248e42188b8d1 Author: Jakub Jelinek <ja...@redhat.com> Date: Fri Oct 4 14:02:13 2024 +0200 diagnostic, pch: Fix up the new diagnostic PCH methods for ubsan checking [PR116936] The PR notes that the new pch_save/pch_restore methods I've added recently invoke UB if either m_classification_history.address () or m_push_list.address () is NULL (which can happen if those vectors are empty (and in the pch_save case nothing has been pushed into them before either). While the corresponding length is necessarily 0, fwrite (NULL, something, 0, f) or fread (NULL, something, 0, f) still invoke UB. The following patch fixes that by not calling fwrite/fread if the corresponding length is 0. 2024-10-04 Jakub Jelinek <ja...@redhat.com> PR pch/116936 * diagnostic.cc (diagnostic_option_classifier::pch_save): Only call fwrite if corresponding length is non-zero. (diagnostic_option_classifier::pch_restore): Only call fread if corresponding length is non-zero.