From: Victor Julien Date: Mon, 24 Oct 2022 11:02:55 +0000 (+0200) Subject: hashlist: use errno style error handling X-Git-Tag: suricata-7.0.0-rc1~233 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e36db9d0e9d785c82a50e832329e3f81bf27e1e;p=thirdparty%2Fsuricata.git hashlist: use errno style error handling --- diff --git a/src/util-hashlist.c b/src/util-hashlist.c index 6866261736..5775e28f49 100644 --- a/src/util-hashlist.c +++ b/src/util-hashlist.c @@ -32,23 +32,29 @@ #include "util-debug.h" #include "util-memcmp.h" -HashListTable* HashListTableInit(uint32_t size, uint32_t (*Hash)(struct HashListTable_ *, void *, uint16_t), char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *)) { - +HashListTable *HashListTableInit(uint32_t size, + uint32_t (*Hash)(struct HashListTable_ *, void *, uint16_t), + char (*Compare)(void *, uint16_t, void *, uint16_t), void (*Free)(void *)) +{ + sc_errno = SC_OK; HashListTable *ht = NULL; if (size == 0) { + sc_errno = SC_EINVAL; goto error; } if (Hash == NULL) { - //printf("ERROR: HashListTableInit no Hash function\n"); + sc_errno = SC_EINVAL; goto error; } /* setup the filter */ ht = SCMalloc(sizeof(HashListTable)); - if (unlikely(ht == NULL)) - goto error; + if (unlikely(ht == NULL)) { + sc_errno = SC_ENOMEM; + goto error; + } memset(ht,0,sizeof(HashListTable)); ht->array_size = size; ht->Hash = Hash; @@ -61,8 +67,10 @@ HashListTable* HashListTableInit(uint32_t size, uint32_t (*Hash)(struct HashList /* setup the bitarray */ ht->array = SCMalloc(ht->array_size * sizeof(HashListTableBucket *)); - if (ht->array == NULL) + if (ht->array == NULL) { + sc_errno = SC_ENOMEM; goto error; + } memset(ht->array,0,ht->array_size * sizeof(HashListTableBucket *)); ht->listhead = NULL;