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) \
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_; \
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_; \
} \
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) \
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_; \
\
\
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) \