summaryrefslogtreecommitdiff
path: root/lib/backupclient
diff options
context:
space:
mode:
authorMartin Ebourne <martin@ebourne.me.uk>2005-12-20 08:13:21 +0000
committerMartin Ebourne <martin@ebourne.me.uk>2005-12-20 08:13:21 +0000
commitdd60d9ad699c056ee7bf7649ef456780df47b521 (patch)
tree7b4ba1d8edf48824e6c9a1a0aad1685f180061b8 /lib/backupclient
parent6ae6b3980e991e265943e2fdc0da776e6b079235 (diff)
Fix CodingChunkAlloc/Free for use on 32 and 64 bit platforms
Diffstat (limited to 'lib/backupclient')
-rw-r--r--lib/backupclient/BackupStoreFile.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/backupclient/BackupStoreFile.h b/lib/backupclient/BackupStoreFile.h
index 627de4ce..446e9422 100644
--- a/lib/backupclient/BackupStoreFile.h
+++ b/lib/backupclient/BackupStoreFile.h
@@ -123,19 +123,20 @@ public:
uint8_t *a = (uint8_t*)malloc((Size) + (BACKUPSTOREFILE_CODING_BLOCKSIZE * 3));
if(a == 0) return 0;
// Align to main block size
- ASSERT(sizeof(uint32_t) == sizeof(void*)); // make sure casting the right pointer size, will need to fix on platforms with 64 bit pointers
- uint32_t adjustment = BACKUPSTOREFILE_CODING_BLOCKSIZE - (((uint32_t)(long)a) % BACKUPSTOREFILE_CODING_BLOCKSIZE);
+ ASSERT(sizeof(unsigned long) >= sizeof(void*)); // make sure casting the right pointer size
+ uint8_t adjustment = BACKUPSTOREFILE_CODING_BLOCKSIZE
+ - (uint8_t)(((unsigned long)a) % BACKUPSTOREFILE_CODING_BLOCKSIZE);
uint8_t *b = (a + adjustment);
// Store adjustment
- *b = (uint8_t)adjustment;
+ *b = adjustment;
// Return offset
return b + BACKUPSTOREFILE_CODING_OFFSET;
}
inline static void CodingChunkFree(void *Block)
{
// Check alignment is as expected
- ASSERT(sizeof(uint32_t) == sizeof(void*)); // make sure casting the right pointer size, will need to fix on platforms with 64 bit pointers
- ASSERT((((uint32_t)(long)Block) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET);
+ ASSERT(sizeof(unsigned long) >= sizeof(void*)); // make sure casting the right pointer size
+ ASSERT((uint8_t)(((unsigned long)Block) % BACKUPSTOREFILE_CODING_BLOCKSIZE) == BACKUPSTOREFILE_CODING_OFFSET);
uint8_t *a = (uint8_t*)Block;
a -= BACKUPSTOREFILE_CODING_OFFSET;
// Adjust downwards...