VectorPtr::back() template method issue
by Dmitry Yanushkevich · in Technical Issues · 06/16/2011 (6:55 am) · 2 replies
Gentlemen,
I believe I have found a serious issue with VectorPtr::back() method. Currently, it is implemented as follows:
which I believe is technically incorrect since iterator returned by end() points behind the last element in a container and, as such, points to an invalid object by definition. It should read like:
or some other way you would prefer. The const methods are vulnerable as well, and I suppose not only in TGB but in all other products using the same tVector.h file.
Kind regards,
Dmitry
I believe I have found a serious issue with VectorPtr::back() method. Currently, it is implemented as follows:
template<class T> inline typename Vector<T>::iterator Vector<T>::end()
{
return mArray + mElementCount;
}
template<class T> inline typename VectorPtr<T>::iterator VectorPtr<T>::end()
{
return (iterator)Parent::end();
}
template<class T> inline T& VectorPtr<T>::back()
{
return *end();
}which I believe is technically incorrect since iterator returned by end() points behind the last element in a container and, as such, points to an invalid object by definition. It should read like:
template<class T> inline T& VectorPtr<T>::back()
{
return *(--end());
}or some other way you would prefer. The const methods are vulnerable as well, and I suppose not only in TGB but in all other products using the same tVector.h file.
Kind regards,
Dmitry
About the author
Worked here and there, did both game and business development. Finally decided to start own business, and here we are -- a cutie Cat Paw Studio has been born! :D
Torque Owner Dmitry Yanushkevich