aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf-index-write.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2018-10-04 22:43:27 -0400
committerSimon Marchi <simon.marchi@ericsson.com>2018-10-04 22:59:44 -0400
commit1f88d0c87c37d3a15fa6376335e8b0d1c79d85aa (patch)
tree211de0a181fb8d8f6ea030ab839fd6bc8d9e0869 /gdb/dwarf-index-write.c
parent1f041c6edf49a896b99db253066fce427a7d2264 (diff)
downloadgdb-1f88d0c87c37d3a15fa6376335e8b0d1c79d85aa.zip
gdb-1f88d0c87c37d3a15fa6376335e8b0d1c79d85aa.tar.gz
gdb-1f88d0c87c37d3a15fa6376335e8b0d1c79d85aa.tar.bz2
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.
Diffstat (limited to 'gdb/dwarf-index-write.c')
-rw-r--r--gdb/dwarf-index-write.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 2520321..d4585af 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -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. */