Skip to content

Commit fdf818b

Browse files
committed
[CoreFoundation] Fix incorrect cast in _CFRuntimeCreateInstance.
_cfinfoa field of CFRuntimeBase is an _Atomic(uint64_t), but for some reason it was being accessed from a uint32_t pointer (which I think violates strict aliasing rules). This was working for little endian architectures, but would have failed for big endian architectures when writing the value back into the MSB instead of the LSB. The fix uses the right size (64 bits) and removes the castings where possible. However, to avoid the _Atomic to be honored, the field is still casted to an uint64_t, which might hide future errors (like the situation this is trying to fix).
1 parent f3bced8 commit fdf818b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

CoreFoundation/Base.subproj/CFRuntime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,10 @@ CFTypeRef _CFRuntimeCreateInstance(CFAllocatorRef allocator, CFTypeID typeID, CF
443443
memset(&memory->_cfinfoa, 0, size - (sizeof(memory->_cfisa) + sizeof(memory->_swift_rc)));
444444

445445
// Set up the cfinfo struct
446-
uint32_t *cfinfop = (uint32_t *)&(memory->_cfinfoa);
446+
uint64_t *cfinfop = (uint64_t *)&(memory->_cfinfoa);
447447
// The 0x80 means we use the default allocator
448-
*cfinfop = (uint32_t)(((uint32_t)typeID << 8) | (0x80));
449-
448+
*cfinfop = ((typeID << 8) | (0x80));
449+
450450
return memory;
451451
#else
452452
if (__CFRuntimeClassTableSize <= typeID) HALT;

0 commit comments

Comments
 (0)