1
0
forked from 0ad/0ad

Avoid overflow identified by /RTCc warning

This was SVN commit r10537.
This commit is contained in:
Ykkrosh 2011-11-14 22:22:38 +00:00
parent 98b62d9733
commit f66a3e726f
2 changed files with 13 additions and 2 deletions

View File

@ -1028,6 +1028,7 @@ public:
m_LosState[idx] |= ((LOS_VISIBLE | LOS_EXPLORED) << (2*(owner-1))); m_LosState[idx] |= ((LOS_VISIBLE | LOS_EXPLORED) << (2*(owner-1)));
} }
ASSERT(counts[idx] < 65535);
counts[idx] = (u16)(counts[idx] + 1); // ignore overflow; the player should never have 64K units counts[idx] = (u16)(counts[idx] + 1); // ignore overflow; the player should never have 64K units
} }
} }
@ -1045,6 +1046,7 @@ public:
for (i32 idx = idx0; idx <= idx1; ++idx) for (i32 idx = idx0; idx <= idx1; ++idx)
{ {
ASSERT(counts[idx] > 0);
counts[idx] = (u16)(counts[idx] - 1); counts[idx] = (u16)(counts[idx] - 1);
// Decreasing from non-zero to zero - move from visible+explored to explored // Decreasing from non-zero to zero - move from visible+explored to explored
@ -1263,10 +1265,14 @@ public:
// Process each of the regions as its own strip. // Process each of the regions as its own strip.
// (If this produces negative-width strips then they'll just get ignored // (If this produces negative-width strips then they'll just get ignored
// which is fine.) // which is fine.)
LosRemoveStripHelper(owner, i0clamp_from, i0clamp_to-1, j, countsData); // (If the strips don't actually overlap (which is very rare with normal unit
LosRemoveStripHelper(owner, i1clamp_to+1, i1clamp_from, j, countsData); // movement speeds), the region between them will be both added and removed,
// so we have to do the add first to avoid overflowing to -1 and triggering
// assertion failures.)
LosAddStripHelper(owner, i0clamp_to, i0clamp_from-1, j, countsData); LosAddStripHelper(owner, i0clamp_to, i0clamp_from-1, j, countsData);
LosAddStripHelper(owner, i1clamp_from+1, i1clamp_to, j, countsData); LosAddStripHelper(owner, i1clamp_from+1, i1clamp_to, j, countsData);
LosRemoveStripHelper(owner, i0clamp_from, i0clamp_to-1, j, countsData);
LosRemoveStripHelper(owner, i1clamp_to+1, i1clamp_from, j, countsData);
} }
} }
} }

View File

@ -110,6 +110,11 @@ public:
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256)-entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); } { CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(256), entity_pos_t::FromInt(256)-entity_pos_t::Epsilon(), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }
cmp->Verify(); cmp->Verify();
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(383), entity_pos_t::FromInt(84), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }
cmp->Verify();
{ CMessagePositionChanged msg(100, true, entity_pos_t::FromInt(348), entity_pos_t::FromInt(83), entity_angle_t::Zero()); cmp->HandleMessage(msg, false); }
cmp->Verify();
WELL512 rng; WELL512 rng;
for (size_t i = 0; i < 1024; ++i) for (size_t i = 0; i < 1024; ++i)
{ {