fixed a bug where votes could potentially select a completely invalid item
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40888
This commit is contained in:
parent
465a3962cb
commit
92e8b40b99
@ -96,7 +96,7 @@ void VoteMenuHandler::DecrementPlayerCount()
|
|||||||
void VoteMenuHandler::EndVoting()
|
void VoteMenuHandler::EndVoting()
|
||||||
{
|
{
|
||||||
unsigned int chosen = 0;
|
unsigned int chosen = 0;
|
||||||
size_t highest = 0;
|
unsigned int highest = 0;
|
||||||
unsigned int dup_count = 0;
|
unsigned int dup_count = 0;
|
||||||
|
|
||||||
/* If we got zero votes, take a shortcut. */
|
/* If we got zero votes, take a shortcut. */
|
||||||
@ -113,7 +113,7 @@ void VoteMenuHandler::EndVoting()
|
|||||||
*/
|
*/
|
||||||
unsigned int dup_array[256];
|
unsigned int dup_array[256];
|
||||||
|
|
||||||
for (size_t i=1; i<m_Votes.size(); i++)
|
for (size_t i=1; i<m_Items; i++)
|
||||||
{
|
{
|
||||||
if (m_Votes[i] > m_Votes[highest])
|
if (m_Votes[i] > m_Votes[highest])
|
||||||
{
|
{
|
||||||
@ -134,7 +134,7 @@ void VoteMenuHandler::EndVoting()
|
|||||||
if (dup_count)
|
if (dup_count)
|
||||||
{
|
{
|
||||||
/* Re-add the original to the list because it's not in there. */
|
/* Re-add the original to the list because it's not in there. */
|
||||||
dup_array[dup_count++] = (unsigned int)highest;
|
dup_array[dup_count++] = highest;
|
||||||
|
|
||||||
/* Pick a random slot. */
|
/* Pick a random slot. */
|
||||||
srand((unsigned int)(time(NULL)));
|
srand((unsigned int)(time(NULL)));
|
||||||
@ -143,7 +143,7 @@ void VoteMenuHandler::EndVoting()
|
|||||||
/* Pick the item. */
|
/* Pick the item. */
|
||||||
chosen = dup_array[r];
|
chosen = dup_array[r];
|
||||||
} else {
|
} else {
|
||||||
chosen = (unsigned int)highest;
|
chosen = highest;
|
||||||
}
|
}
|
||||||
|
|
||||||
picked_item:
|
picked_item:
|
||||||
|
Loading…
Reference in New Issue
Block a user