[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:
Liu Liu
2020-06-25 15:11:38 -07:00
committed by GitHub
parent ca1190a3d8
commit d64078eb27
2 changed files with 4 additions and 3 deletions

View File

@@ -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

View File

@@ -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