summaryrefslogtreecommitdiff
path: root/gcc/vec.h
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-15 07:59:27 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2004-07-15 07:59:27 +0000
commitcd973689fe4b973b03eb6cdc6507540039962c37 (patch)
tree00ea87f0e87cbfc75186c13146ad863fa097b11c /gcc/vec.h
parent6974cd1c60e3adc55a18dcfb23dbc0c285b760d8 (diff)
downloadgcc-cd973689fe4b973b03eb6cdc6507540039962c37.tar.gz
* vec.h (VEC_T_truncate): Allow truncation of an empty vector.
(VEC_T_quick_insert, VEC_T_ordered_remove): Fix sizeof(T) thinko. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84746 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/vec.h')
-rw-r--r--gcc/vec.h18
1 files changed, 10 insertions, 8 deletions
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) \