Skip to content

Commit f34686c

Browse files
authored
Perform unaligned store properly in CaptureStructure.encode(to:). (#185)
Resolves #184.
1 parent bb5a67f commit f34686c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

Sources/_MatchingEngine/Regex/Parse/CaptureStructure.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,10 @@ extension CaptureStructure {
331331
assert(
332332
buffer.count >=
333333
MemoryLayout<SerializationVersion>.stride + MemoryLayout<Code>.stride)
334-
// Encode version.
335-
buffer.storeBytes(
336-
of: Self.currentSerializationVersion, as: SerializationVersion.self)
334+
// Encode version (unaligned store).
335+
withUnsafeBytes(of: Self.currentSerializationVersion) {
336+
buffer.copyMemory(from: $0)
337+
}
337338
// Encode contents.
338339
var offset = MemoryLayout<SerializationVersion>.stride
339340
/// Appends a code to the buffer, advancing the offset to the next position.

0 commit comments

Comments
 (0)