From 73874347374b6130dd55eb851ce7a144795b53ba Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 10 Aug 2012 23:06:54 +0000 Subject: Fix void pointer arithmetic. git-svn-id: http://svn.drobilla.net/zix/trunk@77 df6676b4-ccc9-40e5-b5d6-7c4628a128e3 --- zix/digest.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'zix') diff --git a/zix/digest.c b/zix/digest.c index 4e8e974..04f48f0 100644 --- a/zix/digest.c +++ b/zix/digest.c @@ -31,25 +31,26 @@ zix_digest_start(void) } ZIX_API uint32_t -zix_digest_add(uint32_t hash, const void* buf, const size_t len) +zix_digest_add(uint32_t hash, const void* const buf, const size_t len) { + const uint8_t* str = (const uint8_t*)buf; #ifdef __SSE4_2__ // SSE 4.2 CRC32 for (size_t i = 0; i < (len / sizeof(uint32_t)); ++i) { - hash = _mm_crc32_u32(hash, *(uint32_t*)buf); - buf += sizeof(uint32_t); + hash = _mm_crc32_u32(hash, *(uint32_t*)str); + str += sizeof(uint32_t); } if (len & sizeof(uint16_t)) { - hash = _mm_crc32_u16(hash, *(uint16_t*)buf); - buf += sizeof(uint16_t); + hash = _mm_crc32_u16(hash, *(uint16_t*)str); + str += sizeof(uint16_t); } if (len & sizeof(uint8_t)) { - hash = _mm_crc32_u8(hash, *(uint8_t*)buf); + hash = _mm_crc32_u8(hash, *(uint8_t*)str); } #else // Classic DJB hash for (size_t i = 0; i < len; ++i) { - hash = (hash << 5) + hash + ((const uint8_t*)buf)[i]; + hash = (hash << 5) + hash + str[i]; } #endif return hash; -- cgit v1.2.1