mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Alternative alternative fix for malloc of size 0
Has a short diff to the original code before a4f13ed4a8
.
Supersedes #3353. Thanks for the idea, @timakro.
This commit is contained in:
parent
56a90c25ec
commit
e805e42a94
|
@ -529,12 +529,9 @@ void CDemoPlayer::ScanFile()
|
|||
}
|
||||
|
||||
// copy all the frames to an array instead for fast access
|
||||
if(m_Info.m_SeekablePoints > 0)
|
||||
{
|
||||
m_pKeyFrames = (CKeyFrame *)calloc(m_Info.m_SeekablePoints, sizeof(CKeyFrame));
|
||||
m_pKeyFrames = (CKeyFrame *)calloc(std::max(m_Info.m_SeekablePoints, 1), sizeof(CKeyFrame));
|
||||
for(pCurrentKey = pFirstKey, i = 0; pCurrentKey; pCurrentKey = pCurrentKey->m_pNext, i++)
|
||||
m_pKeyFrames[i] = pCurrentKey->m_Frame;
|
||||
}
|
||||
|
||||
// destroy the temporary heap and seek back to the start
|
||||
io_seek(m_File, StartPos, IOSEEK_START);
|
||||
|
@ -1041,11 +1038,8 @@ int CDemoPlayer::Stop()
|
|||
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "demo_player", "Stopped playback");
|
||||
io_close(m_File);
|
||||
m_File = 0;
|
||||
if(m_pKeyFrames)
|
||||
{
|
||||
free(m_pKeyFrames);
|
||||
m_pKeyFrames = 0;
|
||||
}
|
||||
str_copy(m_aFilename, "", sizeof(m_aFilename));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -270,8 +270,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
Size += str_length(m_lSettings[i].m_aCommand) + 1;
|
||||
}
|
||||
|
||||
// Checked that m_lSettings.size() is not 0, thus Size is > 0 as ell
|
||||
char *pSettings = (char *)malloc(Size); // NOLINT(clang-analyzer-optin.portability.UnixAPI)
|
||||
char *pSettings = (char *)malloc(std::max(Size, 1));
|
||||
char *pNext = pSettings;
|
||||
for(int i = 0; i < m_lSettings.size(); i++)
|
||||
{
|
||||
|
@ -535,11 +534,9 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
PointCount += Item.m_NumPoints;
|
||||
}
|
||||
|
||||
if(PointCount > 0)
|
||||
{
|
||||
// save points
|
||||
int TotalSize = sizeof(CEnvPoint) * PointCount;
|
||||
CEnvPoint *pPoints = (CEnvPoint *)calloc(PointCount, sizeof(*pPoints));
|
||||
CEnvPoint *pPoints = (CEnvPoint *)calloc(std::max(PointCount, 1), sizeof(*pPoints));
|
||||
PointCount = 0;
|
||||
|
||||
for(int e = 0; e < m_lEnvelopes.size(); e++)
|
||||
|
@ -551,7 +548,6 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
|
|||
|
||||
df.AddItem(MAPITEMTYPE_ENVPOINTS, 0, TotalSize, pPoints);
|
||||
free(pPoints);
|
||||
}
|
||||
|
||||
// finish the data file
|
||||
df.Finish();
|
||||
|
|
Loading…
Reference in a new issue