Skip to content

Commit

Permalink
pointee bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Jul 26, 2016
1 parent eff5068 commit 052d1d0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/MySQL/Bind+Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ extension Bind {
return UnsafeMutablePointer<T>(buffer).pointee
}

// must be stored as function because calling pointee
// with garbage value will crash
func len() -> Int {
return Int(cBind.length.pointee) / sizeof(UInt8.self)
}

let isNull = cBind.is_null.pointee
let length = Int(cBind.length.pointee) / sizeof(UInt8.self)

if isNull == 1 {
return .null
Expand All @@ -34,7 +39,7 @@ extension Bind {
if variant == MYSQL_TYPE_JSON {
let buffer = UnsafeMutableBufferPointer(
start: cast(buffer, UInt8.self),
count: length
count: len()
)
let bytes = Array(buffer)

Expand All @@ -57,7 +62,7 @@ extension Bind {
MYSQL_TYPE_SET:
let buffer = UnsafeMutableBufferPointer(
start: cast(buffer, UInt8.self),
count: length
count: len()
)
return .string(buffer.string)
case MYSQL_TYPE_LONG:
Expand Down

0 comments on commit 052d1d0

Please sign in to comment.