mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-01 19:58:15 +00:00
[Swift] Initialize memory when clear ByteBuffer (#5982)
* Initialize memory when clear ByteBuffer It seems (based on my limited understanding) that FlatBuffers requires the writable area to be 0 initialized. However, we missed it when clear the buffer to reinitialize it. This PR fixed that by calling initialize (also fixed the typo) explicitly. * Update version to 0.5.3
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'FlatBuffers'
|
||||
s.version = '0.5.2'
|
||||
s.version = '0.5.3'
|
||||
s.summary = 'FlatBuffers: Memory Efficient Serialization Library'
|
||||
|
||||
s.description = "FlatBuffers is a cross platform serialization library architected for
|
||||
|
||||
@@ -35,7 +35,7 @@ public struct ByteBuffer {
|
||||
memory.copyMemory(from: ptr, byteCount: count)
|
||||
}
|
||||
|
||||
func initalize(for size: Int) {
|
||||
func initialize(for size: Int) {
|
||||
precondition(!unowned)
|
||||
memset(memory, 0, size)
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public struct ByteBuffer {
|
||||
init(initialSize size: Int) {
|
||||
let size = size.convertToPowerofTwo
|
||||
_storage = Storage(count: size, alignment: alignment)
|
||||
_storage.initalize(for: size)
|
||||
_storage.initialize(for: size)
|
||||
}
|
||||
|
||||
/// Constructor that creates a Flatbuffer from unsafe memory region without copying
|
||||
@@ -264,6 +264,7 @@ public struct ByteBuffer {
|
||||
alignment = 1
|
||||
_storage.memory.deallocate()
|
||||
_storage.memory = UnsafeMutableRawPointer.allocate(byteCount: _storage.capacity, alignment: alignment)
|
||||
_storage.initialize(for: _storage.capacity)
|
||||
}
|
||||
|
||||
/// Resizes the buffer size
|
||||
|
||||
Reference in New Issue
Block a user