Fix Miscellaneous Regressions and UBs (#1022)
This commit is contained in:
parent
2164f5191e
commit
28036966a6
@ -227,11 +227,17 @@ private:
|
||||
/* finally, allocate the new block */
|
||||
if (m_Data)
|
||||
{
|
||||
m_Data = (cell_t *)realloc(m_Data, sizeof(cell_t) * m_BlockSize * m_AllocSize);
|
||||
cell_t *data = static_cast<cell_t*>(realloc(m_Data, sizeof(cell_t) * m_BlockSize * m_AllocSize));
|
||||
if (!data) // allocation failure
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Data = data;
|
||||
} else {
|
||||
m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize);
|
||||
m_Data = static_cast<cell_t*>(malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize));
|
||||
}
|
||||
return (m_Data != NULL);
|
||||
return (m_Data != nullptr);
|
||||
}
|
||||
private:
|
||||
cell_t *m_Data;
|
||||
|
@ -416,65 +416,20 @@ void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface)
|
||||
m_ChildDeps.push_back(info);
|
||||
}
|
||||
|
||||
// note: dependency iteration deprecated since 1.10
|
||||
ITERATOR *CExtension::FindFirstDependency(IExtension **pOwner, SMInterface **pInterface)
|
||||
{
|
||||
List<IfaceInfo>::iterator iter = m_Deps.begin();
|
||||
|
||||
if (iter == m_Deps.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pOwner)
|
||||
{
|
||||
*pOwner = (*iter).owner;
|
||||
}
|
||||
if (pInterface)
|
||||
{
|
||||
*pInterface = (*iter).iface;
|
||||
}
|
||||
|
||||
List<IfaceInfo>::iterator *pIter = new List<IfaceInfo>::iterator(iter);
|
||||
|
||||
return (ITERATOR *)pIter;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CExtension::FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface)
|
||||
{
|
||||
List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
|
||||
List<IfaceInfo>::iterator _iter;
|
||||
|
||||
if (_iter == m_Deps.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_iter++;
|
||||
|
||||
if (pOwner)
|
||||
{
|
||||
*pOwner = (*_iter).owner;
|
||||
}
|
||||
if (pInterface)
|
||||
{
|
||||
*pInterface = (*_iter).iface;
|
||||
}
|
||||
|
||||
*pIter = _iter;
|
||||
|
||||
if (_iter == m_Deps.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CExtension::FreeDependencyIterator(ITERATOR *iter)
|
||||
{
|
||||
List<IfaceInfo>::iterator *pIter = (List<IfaceInfo>::iterator *)iter;
|
||||
|
||||
delete pIter;
|
||||
}
|
||||
|
||||
void CExtension::AddInterface(SMInterface *pInterface)
|
||||
|
@ -162,18 +162,16 @@ bool ShareSystem::RequestInterface(const char *iface_name,
|
||||
SMInterface **pIface)
|
||||
{
|
||||
/* See if the interface exists */
|
||||
List<IfaceInfo>::iterator iter;
|
||||
SMInterface *iface;
|
||||
IExtension *iface_owner;
|
||||
IExtension *iface_owner = nullptr;
|
||||
bool found = false;
|
||||
for (iter=m_Interfaces.begin(); iter!=m_Interfaces.end(); iter++)
|
||||
for (auto iter = m_Interfaces.begin(); iter!=m_Interfaces.end(); iter++)
|
||||
{
|
||||
IfaceInfo &info = (*iter);
|
||||
IfaceInfo &info = *iter;
|
||||
iface = info.iface;
|
||||
if (strcmp(iface->GetInterfaceName(), iface_name) == 0)
|
||||
{
|
||||
if (iface->GetInterfaceVersion() == iface_vers
|
||||
|| iface->IsVersionCompatible(iface_vers))
|
||||
if (iface->GetInterfaceVersion() == iface_vers || iface->IsVersionCompatible(iface_vers))
|
||||
{
|
||||
iface_owner = info.owner;
|
||||
found = true;
|
||||
|
@ -381,7 +381,11 @@ public:
|
||||
{
|
||||
if (len > max_size)
|
||||
{
|
||||
buffer = (char *)realloc(buffer, len);
|
||||
auto *newbuffer = static_cast<char *>(realloc(buffer, len));
|
||||
if (!newbuffer)
|
||||
return nullptr;
|
||||
|
||||
buffer = newbuffer;
|
||||
max_size = len;
|
||||
}
|
||||
return buffer;
|
||||
@ -420,7 +424,11 @@ cell_t InternalFormat(IPluginContext *pCtx, const cell_t *params, int start)
|
||||
{
|
||||
if (maxlen > sizeof(g_formatbuf))
|
||||
{
|
||||
__copy_buf = g_extrabuf.GetWithSize(maxlen);
|
||||
char *tmpbuff = g_extrabuf.GetWithSize(maxlen);
|
||||
if (!tmpbuff)
|
||||
return pCtx->ThrowNativeError("Unable to allocate buffer with a size of \"%u\"", maxlen);
|
||||
|
||||
__copy_buf = tmpbuff;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2595,7 +2595,7 @@ static cell_t GetEntityFlags(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
for (int32_t i = 0; i < 32; i++)
|
||||
{
|
||||
int32_t flag = (1<<i);
|
||||
int32_t flag = (1U<<i);
|
||||
if ((actual_flags & flag) == flag)
|
||||
{
|
||||
sm_flags |= SDKEntFlagToSMEntFlag(flag);
|
||||
@ -2641,7 +2641,7 @@ static cell_t SetEntityFlags(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
for (int32_t i = 0; i < 32; i++)
|
||||
{
|
||||
int32_t flag = (1<<i);
|
||||
int32_t flag = (1U<<i);
|
||||
if ((sm_flags & flag) == flag)
|
||||
{
|
||||
actual_flags |= SMEntFlagToSDKEntFlag(flag);
|
||||
|
@ -84,28 +84,28 @@ namespace SourceMod
|
||||
virtual IdentityToken_t *GetIdentity() =0;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the extension dependency list for this extension.
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @param pOwner Optional pointer to store the first interface's owner.
|
||||
* @param pInterface Optional pointer to store the first interface.
|
||||
* @return An ITERATOR pointer for the results, or NULL if no results at all.
|
||||
* @param pOwner Unused
|
||||
* @param pInterface Unused
|
||||
* @return nullptr
|
||||
*/
|
||||
virtual ITERATOR *FindFirstDependency(IExtension **pOwner, SMInterface **pInterface) =0;
|
||||
|
||||
/**
|
||||
* @brief Finds the next dependency in the dependency list.
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @param iter Pointer to iterator from FindFirstDependency.
|
||||
* @param pOwner Optional pointer to store the interface's owner.
|
||||
* @param pInterface Optional pointer to store the interface.
|
||||
* @return True if there are more results after this, false otherwise.
|
||||
* @param iter Unused
|
||||
* @param pOwner Unused
|
||||
* @param pInterface Unused
|
||||
* @return false
|
||||
*/
|
||||
virtual bool FindNextDependency(ITERATOR *iter, IExtension **pOwner, SMInterface **pInterface) =0;
|
||||
|
||||
/**
|
||||
* @brief Frees an ITERATOR handle from FindFirstDependency.
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @param iter Pointer to iterator to free.
|
||||
* @param iter Unused
|
||||
*/
|
||||
virtual void FreeDependencyIterator(ITERATOR *iter) =0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user