rohash: fix codeql warnings

Suspicious pointer scaling to void
pull/10971/head
Victor Julien 2 years ago committed by Victor Julien
parent ea110aca5b
commit 60e6d1d77d

@ -116,11 +116,11 @@ void *ROHashLookup(ROHashTable *table, void *data, uint16_t size)
SCReturnPtr(NULL, "void");
}
uint32_t hash = hashword(data, table->item_size/4, 0) & hashmask(table->hash_bits);
const uint32_t hash = hashword(data, table->item_size / 4, 0) & hashmask(table->hash_bits);
/* get offsets start */
ROHashTableOffsets *os = (void *)table + sizeof(ROHashTable);
ROHashTableOffsets *o = &os[hash];
const ROHashTableOffsets *os = (ROHashTableOffsets *)((uint8_t *)table + sizeof(ROHashTable));
const ROHashTableOffsets *o = &os[hash];
/* no matches */
if (o->cnt == 0) {
@ -186,11 +186,13 @@ int ROHashInitFinalize(ROHashTable *table)
}
ROHashTableItem *item = NULL;
ROHashTableOffsets *os = (void *)table + sizeof(ROHashTable);
ROHashTableOffsets *os = (ROHashTableOffsets *)((uint8_t *)table + sizeof(ROHashTable));
/* count items per hash value */
TAILQ_FOREACH(item, &table->head, next) {
uint32_t hash = hashword((void *)item + sizeof(*item), table->item_size/4, 0) & hashmask(table->hash_bits);
uint32_t hash =
hashword((uint32_t *)((uint8_t *)item + sizeof(*item)), table->item_size / 4, 0) &
hashmask(table->hash_bits);
ROHashTableOffsets *o = &os[hash];
item->pos = o->cnt;
@ -225,13 +227,14 @@ int ROHashInitFinalize(ROHashTable *table)
/* copy each value into the data block */
TAILQ_FOREACH(item, &table->head, next) {
uint32_t hash = hashword((void *)item + sizeof(*item), table->item_size/4, 0) & hashmask(table->hash_bits);
uint32_t hash =
hashword((uint32_t *)((uint8_t *)item + sizeof(*item)), table->item_size / 4, 0) &
hashmask(table->hash_bits);
ROHashTableOffsets *o = &os[hash];
uint32_t offset = (o->offset + item->pos) * table->item_size;
memcpy(table->data + offset, (void *)item + sizeof(*item), table->item_size);
memcpy(table->data + offset, (uint8_t *)item + sizeof(*item), table->item_size);
}
/* clean up temp items */

Loading…
Cancel
Save