1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Fix aliasing issue in physmem.h.

This commit is contained in:
Lasse Collin 2009-02-08 21:35:11 +02:00
parent 0e27028d74
commit 53f7598998

View file

@ -57,17 +57,18 @@ physmem(void)
#elif defined(HAVE_PHYSMEM_SYSCTL) #elif defined(HAVE_PHYSMEM_SYSCTL)
int name[2] = { CTL_HW, HW_PHYSMEM }; int name[2] = { CTL_HW, HW_PHYSMEM };
unsigned long mem; union {
size_t mem_ptr_size = sizeof(mem); unsigned long ul;
if (!sysctl(name, 2, &mem, &mem_ptr_size, NULL, NULL)) { 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". // Some systems use unsigned int as the "return value".
// This makes a difference on 64-bit boxes. // This makes a difference on 64-bit boxes.
if (mem_ptr_size != sizeof(mem)) { if (mem_ptr_size == sizeof(mem.ul))
if (mem_ptr_size == sizeof(unsigned int)) ret = mem.ul;
ret = *(unsigned int *)(&mem); else if (mem_ptr_size == sizeof(mem.ui))
} else { ret = mem.ui;
ret = mem;
}
} }
#elif defined(_WIN32) #elif defined(_WIN32)