Add some fuzzers to test other data structures. (#1870)

Start using a dictionary for fuzzing (see:
https://llvm.org/docs/LibFuzzer.html#dictionaries).
Remove some dead code.
Fuzzing with debug enabled is not usually a great idea (from performance
POV). Keep the code since it might be useful while debugging.
This commit is contained in:
Ivan Nardi
2023-01-25 11:44:59 +01:00
committed by GitHub
parent 29c5cc39fb
commit 9fc724de5a
184 changed files with 436 additions and 60 deletions
+10 -2
View File
@@ -23,15 +23,19 @@ SOFTWARE.
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __DESELMO_LIBCACHE_H__
#define __DESELMO_LIBCACHE_H__
#include <stdint.h>
typedef struct cache_entry *cache_entry;
typedef struct cache_entry_ *cache_entry;
typedef struct cache_entry_map *cache_entry_map;
typedef struct cache_entry_map_ *cache_entry_map;
/**
* @brief Codes representing the result of some functions
@@ -107,3 +111,7 @@ cache_entry cache_entry_new(void);
cache_entry_map cache_entry_map_new(void);
#endif
#ifdef __cplusplus
}
#endif
+5 -5
View File
@@ -58,12 +58,12 @@ struct cache {
cache_entry_map *map;
};
struct cache_entry_map {
struct cache_entry_map_ {
cache_entry entry;
cache_entry_map next;
};
struct cache_entry {
struct cache_entry_ {
void *item;
uint32_t item_size;
cache_entry prev;
@@ -89,10 +89,10 @@ void cache_touch_entry(cache_t cache, cache_entry entry) {
cache_entry cache_entry_new(void) {
return (cache_entry) ndpi_calloc(sizeof(struct cache_entry), 1);
return (cache_entry) ndpi_calloc(sizeof(struct cache_entry_), 1);
}
cache_entry_map cache_entry_map_new(void) {
return (cache_entry_map) ndpi_calloc(sizeof(struct cache_entry_map), 1);
return (cache_entry_map) ndpi_calloc(sizeof(struct cache_entry_map_), 1);
}
cache_t cache_new(uint32_t cache_max_size) {
@@ -192,7 +192,7 @@ cache_result cache_add(cache_t cache, void *item, uint32_t item_size) {
cache_entry_map hash_entry_map = cache->map[hash];
while(hash_entry_map) {
if(tail->item_size == hash_entry_map->entry->item_size &&
!memcmp(tail->item, hash_entry_map->entry->item, item_size)) {
!memcmp(tail->item, hash_entry_map->entry->item, tail->item_size)) {
break;
}