Fix unaligned memory access in import

After extent conversion, the hash is not not aligned anymore,
and we cannot cast anymore to uint32.
This commit is contained in:
Andrea Mazzoleni 2016-01-09 10:06:37 +01:00
parent 9d4fd25774
commit 2f5c6a39a9

View file

@ -48,7 +48,8 @@ int import_block_prevhash_compare(const void* void_arg, const void* void_data)
*/
static inline tommy_uint32_t import_block_hash(const unsigned char* hash)
{
return *(const tommy_uint32_t*)hash;
/* the hash data is not aligned, and we cannot access it with a direct cast */
return hash[0] | ((uint32_t)hash[1] << 8) | ((uint32_t)hash[2] << 16) | ((uint32_t)hash[3] << 24);
}
static void import_file(struct snapraid_state* state, const char* path, uint64_t size)