diff options
author | David Robillard <d@drobilla.net> | 2024-12-11 18:59:43 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-12-11 19:37:21 -0500 |
commit | e1671ccdda0b501e27dd5afdbe05bb31656409a3 (patch) | |
tree | 9604b7fb1ea31c2959fbcc6f9c10ad13af215e82 | |
parent | 34d7e6eb5b0a8a8cc218f96037fbca02849602cb (diff) | |
download | sord-e1671ccdda0b501e27dd5afdbe05bb31656409a3.tar.gz sord-e1671ccdda0b501e27dd5afdbe05bb31656409a3.tar.bz2 sord-e1671ccdda0b501e27dd5afdbe05bb31656409a3.zip |
Calculate node header hash from a separate variable
Really just to avoid passing a buffer smaller than 64 bits to zix_digest().
Although that's safe (it doesn't read beyond the provided size), this is beyond
some static analysis tools. So, avoid false positives by first copying the
relevant header to a size_t variable making it statically obvious that (on
64-bit) 8 bytes of memory are available for reading.
-rw-r--r-- | src/sord.c | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -169,10 +169,12 @@ sord_node_record_key(const SordNode* n) static size_t sord_node_hash(const SordNode* const node) { + const size_t head = node->node.type; + size_t hash = 0U; hash = zix_digest(hash, (const uint8_t*)node->node.buf, node->node.n_bytes); - hash = zix_digest(hash, &node->node.type, sizeof(node->node.type)); + hash = zix_digest(hash, &head, sizeof(head)); if (node->node.type == SERD_LITERAL) { hash = zix_digest(hash, &node->meta.lit, sizeof(node->meta.lit)); } |