1
0
mirror of https://github.com/alliedmodders/metamod-source.git synced 2024-12-01 13:24:25 +01:00

Fixed SourceHook::CVector::resize, hopefully fixed callclass crashbug, add vector test to TestList

--HG--
extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%40205
This commit is contained in:
Pavol Marko 2006-05-19 13:57:04 +00:00
parent 0013d35545
commit c6c4c28db3
3 changed files with 65 additions and 2 deletions

View File

@ -277,7 +277,8 @@ public:
CVector & operator =(const CVector<T> & other)
{
clear();
resize(other.size());
ChangeSize(other.size());
m_CurrentUsedSize = other.size();
for (size_t i=0; i<other.size(); i++)
m_Data[i] = other.at(i);
return *this;
@ -341,9 +342,16 @@ public:
}
bool resize(size_t newSize)
{
return resize(newSize, T());
}
bool resize(size_t newSize, T defval)
{
if (!ChangeSize(newSize))
return false;
for (size_t i = m_CurrentUsedSize; i < newSize; ++i)
m_Data[i] = defval;
m_CurrentUsedSize = newSize;
return true;
}

View File

@ -831,7 +831,7 @@ namespace SourceHook
{
OrigFuncs &tmpvec = m_VT[vtbl_offs];
if (tmpvec.size() <= (size_t)vtbl_idx)
tmpvec.resize(vtbl_idx+1);
tmpvec.resize(vtbl_idx+1, NULL);
tmpvec[vtbl_idx] = orig_entry;
}
void CSourceHookImpl::CCallClassImpl::RemoveCallClassPatch(int vtbl_offs, int vtbl_idx)

View File

@ -2,6 +2,7 @@
#include "sh_list.h"
#include "sh_stack.h"
#include "sh_tinyhash.h"
#include "sh_vector.h"
#include "testevents.h"
// TEST LIST
@ -210,6 +211,57 @@ namespace
return true;
}
bool DoTestVec(std::string &error)
{
typedef SourceHook::CVector<int> IntVector;
IntVector vec1;
IntVector::iterator iter;
int i;
CHECK_COND(vec1.size() == 0 && vec1.empty(), "V1");
for (i = 0; i < 500; ++i)
vec1.push_back(i);
CHECK_COND(vec1.size() == 500 && !vec1.empty(), "V2");
for (i = 0; i < 500; ++i)
CHECK_COND(vec1[i] == i, "V3");
for (i = 0, iter = vec1.begin(); iter != vec1.end(); ++iter, ++i)
CHECK_COND(*iter == i, "V4");
vec1.resize(1000);
for (i = 0; i < 500; ++i)
CHECK_COND(vec1[i] == i, "V5.1");
for (i = 500; i < 1000; ++i)
CHECK_COND(vec1[i] == 0, "V5.2");
vec1.resize(200);
for (i = 0; i < 200; ++i)
CHECK_COND(vec1[i] == i, "V6");
vec1.resize(500, 0x12345678);
for (i = 0; i < 200; ++i)
CHECK_COND(vec1[i] == i, "V7.1");
for (i = 200; i < 500; ++i)
CHECK_COND(vec1[i] == 0x12345678, "V7.2");
IntVector vec2(vec1);
CHECK_COND(vec2.size() == vec1.size() && vec2.empty() == vec1.empty(), "V8.0");
for (i = 0; i < 200; ++i)
CHECK_COND(vec2[i] == i, "V8.1");
for (i = 200; i < 500; ++i)
CHECK_COND(vec2[i] == 0x12345678, "V8.2");
vec1.clear();
CHECK_COND(vec1.size() == 0 && vec1.empty() && vec1.begin() == vec1.end(), "V9");
vec2 = vec1;
CHECK_COND(vec2.size() == 0 && vec2.empty() && vec2.begin() == vec2.end(), "V9");
return true;
}
}
bool TestList(std::string &error)
@ -223,5 +275,8 @@ bool TestList(std::string &error)
if (!DoTestStack(error))
return false;
if (!DoTestVec(error))
return false;
return true;
}