From 6645358fedb36e7966e3d1a8d22d834d04430e6d Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Sun, 10 May 2015 22:30:07 +0000 Subject: [PATCH] fix issue #57: undefined behavior in bit_vector.h --- src/util/bit_vector.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/bit_vector.h b/src/util/bit_vector.h index 6738ba0aa..43b0e9619 100644 --- a/src/util/bit_vector.h +++ b/src/util/bit_vector.h @@ -75,8 +75,11 @@ public: bit_vector(bit_vector const & source): m_num_bits(source.m_num_bits), m_capacity(source.m_capacity), - m_data(alloc_svect(unsigned, source.m_capacity)) { - memcpy(m_data, source.m_data, source.m_capacity * sizeof(unsigned)); + m_data(0) { + if (source.m_data) { + m_data = alloc_svect(unsigned, m_capacity); + memcpy(m_data, source.m_data, m_capacity * sizeof(unsigned)); + } } bit_vector(unsigned const * source, int num_bits): @@ -183,6 +186,9 @@ public: bool operator!=(bit_vector const & other) const { return !operator==(other); } bit_vector & operator=(bit_vector const & source) { + if (!source.m_data) + return *this; + m_num_bits = source.m_num_bits; if (m_capacity < source.m_capacity) { dealloc_svect(m_data);