From 73453996a99336f6f025b9c21765cd66ac08c8e9 Mon Sep 17 00:00:00 2001 From: steve Date: Sat, 27 Aug 2005 03:28:16 +0000 Subject: [PATCH] Be more cautios about accessing out-of-range bits. --- vvp/vvp_net.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/vvp/vvp_net.cc b/vvp/vvp_net.cc index 38301143f..5062c33a4 100644 --- a/vvp/vvp_net.cc +++ b/vvp/vvp_net.cc @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ident "$Id: vvp_net.cc,v 1.42 2005/08/27 02:34:43 steve Exp $" +#ident "$Id: vvp_net.cc,v 1.43 2005/08/27 03:28:16 steve Exp $" # include "config.h" # include "vvp_net.h" @@ -450,15 +450,23 @@ bool vvp_vector4_t::eeq(const vvp_vector4_t&that) const if (size_ != that.size_) return false; - if (size_ <= BITS_PER_WORD) - return bits_val_ == that.bits_val_; + if (size_ <= BITS_PER_WORD) { + unsigned long mask = (1UL << 2UL * size_) - 1; + return (bits_val_&mask) == (that.bits_val_&mask); + } - unsigned words = (size_+BITS_PER_WORD-1) / BITS_PER_WORD; + unsigned words = size_ / BITS_PER_WORD; for (unsigned idx = 0 ; idx < words ; idx += 1) { if (bits_ptr_[idx] != that.bits_ptr_[idx]) return false; } + unsigned long mask = size_%BITS_PER_WORD; + if (mask > 0) { + mask = (1UL << 2UL*mask) - 1; + return (bits_ptr_[words]&mask) == (that.bits_ptr_[words]&mask); + } + return true; } @@ -1631,6 +1639,9 @@ vvp_bit4_t compare_gtge_signed(const vvp_vector4_t&a, /* * $Log: vvp_net.cc,v $ + * Revision 1.43 2005/08/27 03:28:16 steve + * Be more cautios about accessing out-of-range bits. + * * Revision 1.42 2005/08/27 02:34:43 steve * Bring threads into the vvp_vector4_t structure. *