aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2009-02-08 21:35:11 +0200
committerLasse Collin <lasse.collin@tukaani.org>2009-02-08 21:35:11 +0200
commit53f7598998b1860a69c51243b5d2e34623c6bf60 (patch)
tree9c001db46f8ce939ba49d9703afbf88f5b77c07d /src/common
parentAdd a separate internal function to initialize the CRC32 (diff)
downloadxz-53f7598998b1860a69c51243b5d2e34623c6bf60.tar.xz
Fix aliasing issue in physmem.h.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/physmem.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/common/physmem.h b/src/common/physmem.h
index a0e72c8e..c9d50394 100644
--- a/src/common/physmem.h
+++ b/src/common/physmem.h
@@ -57,17 +57,18 @@ physmem(void)
#elif defined(HAVE_PHYSMEM_SYSCTL)
int name[2] = { CTL_HW, HW_PHYSMEM };
- unsigned long mem;
- size_t mem_ptr_size = sizeof(mem);
- if (!sysctl(name, 2, &mem, &mem_ptr_size, NULL, NULL)) {
+ union {
+ unsigned long ul;
+ unsigned int ui;
+ } mem;
+ size_t mem_ptr_size = sizeof(mem.ul);
+ if (!sysctl(name, 2, &mem.ul, &mem_ptr_size, NULL, NULL)) {
// Some systems use unsigned int as the "return value".
// This makes a difference on 64-bit boxes.
- if (mem_ptr_size != sizeof(mem)) {
- if (mem_ptr_size == sizeof(unsigned int))
- ret = *(unsigned int *)(&mem);
- } else {
- ret = mem;
- }
+ if (mem_ptr_size == sizeof(mem.ul))
+ ret = mem.ul;
+ else if (mem_ptr_size == sizeof(mem.ui))
+ ret = mem.ui;
}
#elif defined(_WIN32)