mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-11-24 18:44:20 +08:00
Fix undefined behavior, don't pass NULL to fwrite
If a vector that we try to write using file_write is empty, we may end up passing NULL to fwrite, which triggers UBSan: .../gdb/dwarf-index-write.c:73:14: runtime error: null pointer passed as argument 1, which is declared to never be null Avoid it by skipping the write if the vector is empty. gdb/ChangeLog: * dwarf-index-write.c (file_write): Don't write if the vector is empty.
This commit is contained in:
parent
1f041c6edf
commit
1f88d0c87c
@ -1,3 +1,8 @@
|
||||
2018-10-04 Simon Marchi <simon.marchi@ericsson.com>
|
||||
|
||||
* dwarf-index-write.c (file_write): Don't write if the vector is
|
||||
empty.
|
||||
|
||||
2018-10-05 Tom de Vries <tdevries@suse.de>
|
||||
|
||||
* python/py-progspace.c (pspy_solib_name): Fix type mismatch in
|
||||
|
@ -80,7 +80,8 @@ template<typename Elem, typename Alloc>
|
||||
static void
|
||||
file_write (FILE *file, const std::vector<Elem, Alloc> &vec)
|
||||
{
|
||||
file_write (file, vec.data (), vec.size () * sizeof (vec[0]));
|
||||
if (!vec.empty ())
|
||||
file_write (file, vec.data (), vec.size () * sizeof (vec[0]));
|
||||
}
|
||||
|
||||
/* In-memory buffer to prepare data to be written later to a file. */
|
||||
|
Loading…
Reference in New Issue
Block a user