-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve TeamsInfoRec::Add_Team function #638
base: develop
Are you sure you want to change the base?
Conversation
93ab2f0
to
915bd55
Compare
e02f9f7
to
8894060
Compare
8894060
to
73be557
Compare
@@ -30,36 +30,31 @@ TeamsInfoRec::~TeamsInfoRec() | |||
*/ | |||
void TeamsInfoRec::Add_Team(const Dict *team) | |||
{ | |||
captainslog_dbgassert(m_numTeams < 2048, "%d teams have been allocated (so far). This seems excessive.", m_numTeams); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As seen in world builder
// If we have too many teams for our current allocation to handle, reallocate more. | ||
if (m_numTeams >= m_numTeamsAllocated) { | ||
TeamsInfo *ti = new TeamsInfo[m_numTeamsAllocated + TEAMINFO_GROWTH_STEP]; | ||
const int allocsz = m_numTeamsAllocated + TEAMINFO_GROWTH_STEP; | ||
captainslog_assert(m_numTeams < allocsz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this assert for good measure.
|
||
// Copy existing data across to new array. | ||
int i; | ||
for (i = 0; i < m_numTeams; ++i) { | ||
int i = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helped avoid complaint from static analyzer I think.
m_teams = ti; | ||
m_numTeamsAllocated += TEAMINFO_GROWTH_STEP; | ||
} | ||
|
||
m_teams[m_numTeams].Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the test are removed, because it already happens inside the Init
function called below.
Static analyzer still warns about
m_teams[m_numTeams++].Init(team);
buffer overrun but algorithm looks ok to me.