Skip to content

Potential bug in map->spare usage (used both as struct bucket and stored item) #34

@HeavenlyAwe

Description

@HeavenlyAwe

In the initialize function map->spare is initialized to have sizeof(hashmap) + 2 * bucketsz

But it is used both as struct bucket and as the items stored in the buckets in the setter and getter.

hashmap.c/hashmap.c

Lines 280 to 290 in 84d0d3b

{
memcpy(map->spare, bitem, map->elsize);
memcpy(bitem, eitem, map->elsize);
return map->spare;
}
if (bucket->dib < entry->dib) {
memcpy(map->spare, bucket, map->bucketsz);
memcpy(bucket, entry, map->bucketsz);
memcpy(entry, map->spare, map->bucketsz);
eitem = bucket_item(entry);
}

memcpy(map->spare, bitem, map->elsize);

As long as elsize is smaller than bucketsz this shouldn't be a problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions