diff options
author | Nikolay Korolev <nickvnuk@gmail.com> | 2020-11-30 00:15:03 +0100 |
---|---|---|
committer | Nikolay Korolev <nickvnuk@gmail.com> | 2020-11-30 00:15:03 +0100 |
commit | 8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c (patch) | |
tree | 96d47ee1d5f21a833726c197990683663b340e55 /src/core/templates.h | |
parent | Merge pull request #841 from aap/master (diff) | |
download | re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.tar re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.tar.gz re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.tar.bz2 re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.tar.lz re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.tar.xz re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.tar.zst re3-8f05ccd6c4608172ae4c9a589d2b2c4ce915eb2c.zip |
Diffstat (limited to 'src/core/templates.h')
-rw-r--r-- | src/core/templates.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/core/templates.h b/src/core/templates.h index 86239664..166f865c 100644 --- a/src/core/templates.h +++ b/src/core/templates.h @@ -124,12 +124,18 @@ public: (T*)&m_entries[handle >> 8] : nil; } int GetIndex(T *entry){ - int i = GetJustIndex(entry); + int i = GetJustIndex_NoFreeAssert(entry); return m_flags[i].u + (i<<8); } int GetJustIndex(T *entry){ - // TODO: the cast is unsafe - return (int)((U*)entry - m_entries); + int index = GetJustIndex_NoFreeAssert(entry); + assert(!IsFreeSlot(index)); + return index; + } + int GetJustIndex_NoFreeAssert(T* entry){ + int index = ((U*)entry - m_entries); + assert((U*)entry == (U*)&m_entries[index]); // cast is unsafe - check required + return index; } int GetNoOfUsedSpaces(void) const{ int i; |