From 400053660cdd089c226a6f6fdb4e6793c6384f16 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Thu, 15 Jul 2004 07:59:27 +0000 Subject: [PATCH] vec.h (VEC_T_truncate): Allow truncation of an empty vector. * vec.h (VEC_T_truncate): Allow truncation of an empty vector. (VEC_T_quick_insert, VEC_T_ordered_remove): Fix sizeof(T) thinko. From-SVN: r84746 --- gcc/ChangeLog | 5 +++++ gcc/vec.h | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0448de842ad..b76a1c34639 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-07-15 Nathan Sidwell + + * vec.h (VEC_T_truncate): Allow truncation of an empty vector. + (VEC_T_quick_insert, VEC_T_ordered_remove): Fix sizeof(T) thinko. + 2004-07-14 Richard Henderson * print-tree.c (print_node): Fix casts last change. diff --git a/gcc/vec.h b/gcc/vec.h index 352d3474eb5..f795ba13f0b 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -382,8 +382,9 @@ static inline TDEF VEC_OP (TDEF,pop) \ static inline void VEC_OP (TDEF,truncate) \ (VEC (TDEF) *vec_, size_t size_) \ { \ - VEC_ASSERT (vec_->num >= size_, "truncate", TDEF); \ - vec_->num = size_; \ + VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \ + if (vec_) \ + vec_->num = size_; \ } \ \ static inline TDEF VEC_OP (TDEF,replace) \ @@ -406,7 +407,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \ VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \ VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \ slot_ = &vec_->vec[ix_]; \ - memmove (slot_ + 1, slot_, vec_->num++ - ix_); \ + memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (TDEF)); \ *slot_ = obj_; \ \ return slot_; \ @@ -429,7 +430,7 @@ static inline TDEF VEC_OP (TDEF,ordered_remove) \ VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \ slot_ = &vec_->vec[ix_]; \ obj_ = *slot_; \ - memmove (slot_, slot_ + 1, --vec_->num - ix_); \ + memmove (slot_, slot_ + 1, (--vec_->num - ix_) * sizeof (TDEF)); \ \ return obj_; \ } \ @@ -553,8 +554,9 @@ static inline void VEC_OP (TDEF,pop) \ static inline void VEC_OP (TDEF,truncate) \ (VEC (TDEF) *vec_, size_t size_) \ { \ - VEC_ASSERT (vec_->num >= size_, "truncate", TDEF); \ - vec_->num = size_; \ + VEC_ASSERT (vec_ ? vec_->num >= size_ : !size_, "truncate", TDEF); \ + if (vec_) \ + vec_->num = size_; \ } \ \ static inline TDEF *VEC_OP (TDEF,replace) \ @@ -578,7 +580,7 @@ static inline TDEF *VEC_OP (TDEF,quick_insert) \ VEC_ASSERT (vec_->num < vec_->alloc, "insert", TDEF); \ VEC_ASSERT (ix_ <= vec_->num, "insert", TDEF); \ slot_ = &vec_->vec[ix_]; \ - memmove (slot_ + 1, slot_, vec_->num++ - ix_); \ + memmove (slot_ + 1, slot_, (vec_->num++ - ix_) * sizeof (TDEF)); \ if (obj_) \ *slot_ = *obj_; \ \ @@ -600,7 +602,7 @@ static inline void VEC_OP (TDEF,ordered_remove) \ \ VEC_ASSERT (ix_ < vec_->num, "remove", TDEF); \ slot_ = &vec_->vec[ix_]; \ - memmove (slot_, slot_ + 1, --vec_->num - ix_); \ + memmove (slot_, slot_ + 1, (--vec_->num - ix_) * sizeof (TDEF)); \ } \ \ static inline void VEC_OP (TDEF,unordered_remove) \ -- 2.30.2