]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
storage: use proper type instead of void ptr
authorVictor Julien <vjulien@oisf.net>
Fri, 24 Nov 2023 18:28:17 +0000 (19:28 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 1 Dec 2023 13:55:37 +0000 (14:55 +0100)
src/util-storage.c
src/util-storage.h

index aec5c1d10fc6f6455992d68d7d7ff93f758a8c67..493b139ee85f844aee2f44f86914886e1630aca0 100644 (file)
@@ -218,7 +218,7 @@ void *StorageGetById(const Storage *storage, const StorageEnum type, const int i
     SCLogDebug("storage %p id %d", storage, id);
     if (storage == NULL)
         return NULL;
-    return storage[id];
+    return storage[id].ptr;
 }
 
 int StorageSetById(Storage *storage, const StorageEnum type, const int id, void *ptr)
@@ -229,7 +229,7 @@ int StorageSetById(Storage *storage, const StorageEnum type, const int id, void
     SCLogDebug("storage %p id %d", storage, id);
     if (storage == NULL)
         return -1;
-    storage[id] = ptr;
+    storage[id].ptr = ptr;
     return 0;
 }
 
@@ -241,14 +241,14 @@ void *StorageAllocByIdPrealloc(Storage *storage, StorageEnum type, int id)
     SCLogDebug("storage %p id %d", storage, id);
 
     StorageMapping *map = &storage_map[type][id];
-    if (storage[id] == NULL && map->Alloc != NULL) {
-        storage[id] = map->Alloc(map->size);
-        if (storage[id] == NULL) {
+    if (storage[id].ptr == NULL && map->Alloc != NULL) {
+        storage[id].ptr = map->Alloc(map->size);
+        if (storage[id].ptr == NULL) {
             return NULL;
         }
     }
 
-    return storage[id];
+    return storage[id].ptr;
 }
 
 void StorageFreeById(Storage *storage, StorageEnum type, int id)
@@ -265,10 +265,10 @@ void StorageFreeById(Storage *storage, StorageEnum type, int id)
     Storage *store = storage;
     if (store != NULL) {
         SCLogDebug("store %p", store);
-        if (store[id] != NULL) {
+        if (store[id].ptr != NULL) {
             StorageMapping *map = &storage_map[type][id];
-            map->Free(store[id]);
-            store[id] = NULL;
+            map->Free(store[id].ptr);
+            store[id].ptr = NULL;
         }
     }
 }
@@ -288,10 +288,10 @@ void StorageFreeAll(Storage *storage, StorageEnum type)
     Storage *store = storage;
     int i;
     for (i = 0; i < storage_max_id[type]; i++) {
-        if (store[i] != NULL) {
+        if (store[i].ptr != NULL) {
             StorageMapping *map = &storage_map[type][i];
-            map->Free(store[i]);
-            store[i] = NULL;
+            map->Free(store[i].ptr);
+            store[i].ptr = NULL;
         }
     }
 }
index 6942ec2f2b8220d8caede053d86b145206b76dec..6866874f7deb77c1a8c0c35c388834666af9d849 100644 (file)
@@ -36,7 +36,9 @@ typedef enum StorageEnum_ {
 } StorageEnum;
 
 /** void ptr array for now */
-typedef void* Storage;
+typedef struct Storage {
+    void *ptr;
+} Storage;
 
 void StorageInit(void);
 void StorageCleanup(void);