X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcontainer_bloomfilter.c;h=6e8fc78377f4db6ec600e423222752072bc60c3d;hb=8226d9807819dbbc4b05751f4cdd09603832367d;hp=8e44f4fc673d2ca1c72a6a8df1ca9851dd4c4d7e;hpb=652e89b59ed2207c2c12172fdabcd6e659995c81;p=oweals%2Fgnunet.git diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c index 8e44f4fc6..6e8fc7837 100644 --- a/src/util/container_bloomfilter.c +++ b/src/util/container_bloomfilter.c @@ -433,6 +433,14 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename, } /* Alloc block */ bf->bitArray = GNUNET_malloc_large (size); + if (bf->bitArray == NULL) + { + if (bf->fh != NULL) + GNUNET_DISK_file_close (bf->fh); + GNUNET_free_non_null (bf->filename); + GNUNET_free (bf); + return NULL; + } bf->bitArraySize = size; bf->addressesPerElement = k; memset (bf->bitArray, 0, bf->bitArraySize); @@ -505,6 +513,11 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data, bf->filename = NULL; bf->fh = NULL; bf->bitArray = GNUNET_malloc_large (size); + if (bf->bitArray == NULL) + { + GNUNET_free (bf); + return NULL; + } bf->bitArraySize = size; bf->addressesPerElement = k; if (data != NULL) @@ -625,14 +638,21 @@ GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, const char *data, size_t size) { unsigned int i; + unsigned int n; + unsigned long long* fc; + const unsigned long long* dc; if (NULL == bf) return GNUNET_YES; if (bf->bitArraySize != size) return GNUNET_SYSERR; - /* FIXME: we could do this 4-8x faster by - going over int/long arrays */ - for (i = 0; i < size; i++) + fc = (unsigned long long*) bf->bitArray; + dc = (const unsigned long long*) data; + n = size / sizeof (unsigned long long); + + for (i = 0; i < n; i++) + fc[i] |= dc[i]; + for (i = n * sizeof(unsigned long long); i < size; i++) bf->bitArray[i] |= data[i]; return GNUNET_OK; }