Fixed a bug where a value past the end of an array could be read
(though it would never be used). git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1417 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -230,18 +230,26 @@ nextPower2(uio_uint32 x) {
|
|||||||
// there are outstanding iterators.
|
// there are outstanding iterators.
|
||||||
HASHTABLE_(Iterator) *
|
HASHTABLE_(Iterator) *
|
||||||
HASHTABLE_(getIterator)(const HASHTABLE_(HashTable) *hashTable) {
|
HASHTABLE_(getIterator)(const HASHTABLE_(HashTable) *hashTable) {
|
||||||
HASHTABLE_(Iterator) *result;
|
HASHTABLE_(Iterator) *iterator;
|
||||||
uio_uint32 i;
|
uio_uint32 i;
|
||||||
|
|
||||||
result = uio_malloc(sizeof (HASHTABLE_(Iterator)));
|
iterator = uio_malloc(sizeof (HASHTABLE_(Iterator)));
|
||||||
result->hashTable = hashTable;
|
iterator->hashTable = hashTable;
|
||||||
i = 0;
|
|
||||||
while (i < hashTable->size &&
|
// Look for the first used bucket.
|
||||||
hashTable->entries[i] == NULL)
|
for (i = 0; i < iterator->hashTable->size; i++) {
|
||||||
i++;
|
if (iterator->hashTable->entries[i] != NULL) {
|
||||||
result->bucketNr = i;
|
// Found a used bucket.
|
||||||
result->entry = hashTable->entries[i];
|
iterator->bucketNr = i;
|
||||||
return result;
|
iterator->entry = iterator->hashTable->entries[i];
|
||||||
|
return iterator;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No entries were found.
|
||||||
|
iterator->bucketNr = i;
|
||||||
|
iterator->entry = NULL;
|
||||||
|
return iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -259,22 +267,29 @@ HASHTABLE_(iteratorValue)(HASHTABLE_(Iterator) *iterator) {
|
|||||||
return iterator->entry->value;
|
return iterator->entry->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Should not be called if the iterator is already past the last entry.
|
||||||
HASHTABLE_(Iterator) *
|
HASHTABLE_(Iterator) *
|
||||||
HASHTABLE_(iteratorNext)(HASHTABLE_(Iterator) *iterator) {
|
HASHTABLE_(iteratorNext)(HASHTABLE_(Iterator) *iterator) {
|
||||||
uio_uint32 i;
|
uio_uint32 i;
|
||||||
|
|
||||||
if (iterator->entry != NULL) {
|
// If there's another entry in this bucket, use that.
|
||||||
iterator->entry = iterator->entry->next;
|
iterator->entry = iterator->entry->next;
|
||||||
if (iterator->entry != NULL)
|
if (iterator->entry != NULL)
|
||||||
|
return iterator;
|
||||||
|
|
||||||
|
// Look for the next used bucket.
|
||||||
|
for (i = iterator->bucketNr + 1; i < iterator->hashTable->size; i++) {
|
||||||
|
if (iterator->hashTable->entries[i] != NULL) {
|
||||||
|
// Found another used bucket.
|
||||||
|
iterator->bucketNr = i;
|
||||||
|
iterator->entry = iterator->hashTable->entries[i];
|
||||||
return iterator;
|
return iterator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
i = iterator->bucketNr + 1;
|
// No more entries were found.
|
||||||
while (i < iterator->hashTable->size &&
|
|
||||||
iterator->hashTable->entries[i] == NULL)
|
|
||||||
i++;
|
|
||||||
iterator->bucketNr = i;
|
iterator->bucketNr = i;
|
||||||
iterator->entry = iterator->hashTable->entries[i];
|
iterator->entry = NULL;
|
||||||
return iterator;
|
return iterator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user