]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostic, pch: Fix up the new diagnostic PCH methods for ubsan checking [PR116936]
authorJakub Jelinek <jakub@redhat.com>
Fri, 4 Oct 2024 12:02:13 +0000 (14:02 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 4 Oct 2024 12:02:13 +0000 (14:02 +0200)
commitf82055f8247478d9e2c00f2a442248e42188b8d1
tree6e4b1b74e0203bab0c29cb028d8c051e81714ab0
parent92e9e971ced90af5a825ae4b35ad6c98c9ab86da
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  <jakub@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.
gcc/diagnostic.cc