vec.h (VEC_T_truncate): Allow truncation of an empty vector.
authorNathan Sidwell <nathan@codesourcery.com>
Thu, 15 Jul 2004 07:59:27 +0000 (07:59 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Thu, 15 Jul 2004 07:59:27 +0000 (07:59 +0000)
* 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
gcc/vec.h

index 0448de842adc3783e1957a1494183516249a95db..b76a1c346394dc0e758c68fde47fb89426244bac 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-15  Nathan Sidwell  <nathan@codesourcery.com>
+
+       * 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  <rth@redhat.com>
 
        * print-tree.c (print_node): Fix casts last change.
index 352d3474eb5faceac08fd3b5f5b97618a3ccaef5..f795ba13f0bb5c88200a481d0f1af424cca62c43 100644 (file)
--- 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)                        \