Added test cases for sid allocation.

This revealed a few bugs:
* when sid allocator is full, then uhub will loop indefinitely when allocating one more (unlikely to occur).
* looking up a user object based on a sid that is out of range (off by one) returns invalid memory.
This commit is contained in:
Jan Vidar Krey
2010-02-18 16:02:13 +01:00
parent 963416ad73
commit 59ed268f4d
3 changed files with 154 additions and 7 deletions

View File

@@ -119,6 +119,14 @@ void sid_pool_destroy(struct sid_pool* pool)
sid_t sid_alloc(struct sid_pool* pool, struct hub_user* user)
{
if (pool->count >= (pool->max - pool->min))
{
#ifdef DEBUG_SID
LOG_DUMP("SID_POOL: alloc, sid pool is full.");
#endif
return 0;
}
sid_t n = (++pool->count);
for (; (pool->map[n % pool->max]); n++) ;
@@ -140,7 +148,7 @@ void sid_free(struct sid_pool* pool, sid_t sid)
struct hub_user* sid_lookup(struct sid_pool* pool, sid_t sid)
{
if (!sid || (sid > pool->max))
if (!sid || (sid >= pool->max))
return 0;
return pool->map[sid];
}