From 6bc661e907f5382dbd9a76fb47a3b554c2ea0028 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 13 Jan 2014 17:58:20 +0100 Subject: attrs: Allow NULL attribute to be passed to p11_attr_hash() This allows simpler lookups. https://bugs.freedesktop.org/show_bug.cgi?id=73558 --- common/attrs.c | 12 +++++++----- common/tests/test-attrs.c | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/common/attrs.c b/common/attrs.c index 9f3e522..4a3d655 100644 --- a/common/attrs.c +++ b/common/attrs.c @@ -508,12 +508,14 @@ unsigned int p11_attr_hash (const void *data) { const CK_ATTRIBUTE *attr = data; - uint32_t hash; + uint32_t hash = 0; - p11_hash_murmur3 (&hash, - &attr->type, sizeof (attr->type), - attr->pValue, (size_t)attr->ulValueLen, - NULL); + if (attr != NULL) { + p11_hash_murmur3 (&hash, + &attr->type, sizeof (attr->type), + attr->pValue, (size_t)attr->ulValueLen, + NULL); + } return hash; } diff --git a/common/tests/test-attrs.c b/common/tests/test-attrs.c index 6087191..79895e2 100644 --- a/common/tests/test-attrs.c +++ b/common/tests/test-attrs.c @@ -454,6 +454,9 @@ test_hash (void) assert (p11_attr_hash (&overflow) != hash); assert (p11_attr_hash (&null) != hash); assert (p11_attr_hash (&content) != hash); + + hash = p11_attr_hash (NULL); + assert (hash == 0); } static void -- cgit v1.2.1