Skip to content

Commit 19e801f

Browse files
committed
bug fix for header message size
1 parent defe411 commit 19e801f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Sources/Mach/Core/Messaging/Message.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ extension Mach {
5454
)
5555

5656
// Write the header.
57-
serializingPointer.bindMemory(to: mach_msg_header_t.self, capacity: 1).pointee =
57+
let headerPointer = serializingPointer.bindMemory(
58+
to: mach_msg_header_t.self, capacity: 1
59+
)
60+
headerPointer.pointee =
5861
self.header // This is pass-by-value, so we don't have to worry about what happens if `self.header` changes later.
5962
serializingPointer += MemoryLayout<mach_msg_header_t>.size
6063

@@ -84,10 +87,10 @@ extension Mach {
8487
// field), we still need to be able to deserialize this raw representation back into a `MachMessage`. Thus, we
8588
// set it to what the kernel would set it to. The kernel allegedly ignores this field for sent messages, so it
8689
// should be safe to set it here. If the value is non-zero, we leave it as-is and assume it's purposeful.
87-
if self.header.msgh_size == 0 {
90+
if headerPointer.pointee.msgh_size == 0 {
8891
// `serializingPointer` sould be at the end of the payload, so we can calculate the size of the message.
8992
let payloadEndPointer = serializingPointer
90-
self.header.msgh_size = mach_msg_size_t(payloadEndPointer - startPointer)
93+
headerPointer.pointee.msgh_size = mach_msg_size_t(payloadEndPointer - startPointer)
9194
}
9295

9396
// Realign the pointer after writing an arbitrarily-sized payload.

0 commit comments

Comments
 (0)