فهرست منبع

assert() on iterator call

Daniele Bartolini 13 سال پیش
والد
کامیت
6724b601dc
1فایلهای تغییر یافته به همراه10 افزوده شده و 2 حذف شده
  1. 10 2
      src/core/containers/List.h

+ 10 - 2
src/core/containers/List.h

@@ -344,6 +344,8 @@ inline const List<T>& List<T>::operator=(const List<T>& other)
 template <typename T>
 template <typename T>
 inline const T* List<T>::begin() const
 inline const T* List<T>::begin() const
 {
 {
+	assert(m_size > 0);
+
 	return m_array;
 	return m_array;
 }
 }
 
 
@@ -351,6 +353,8 @@ inline const T* List<T>::begin() const
 template <typename T>
 template <typename T>
 inline T* List<T>::begin()
 inline T* List<T>::begin()
 {
 {
+	assert(m_size > 0);
+
 	return m_array;
 	return m_array;
 }
 }
 
 
@@ -358,14 +362,18 @@ inline T* List<T>::begin()
 template <typename T>
 template <typename T>
 inline const T* List<T>::end() const
 inline const T* List<T>::end() const
 {
 {
-	return m_array + (m_size - 1);
+	assert(m_size > 0);
+
+	return &m_array[m_size - 1];
 }
 }
 
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 template <typename T>
 template <typename T>
 inline T* List<T>::end()
 inline T* List<T>::end()
 {
 {
-	return m_array + (m_size - 1);
+	assert(m_size > 0);
+
+	return &m_array[m_size - 1];
 }
 }
 
 
 } // namespace crown
 } // namespace crown