Skip to content

Commit 463c523

Browse files
sjanuarymattcolegate
authored andcommitted
Copy all Strings received from agentcore instead of using raw pointer (#126)
* Add debug to diagnose test crash on Travis * Try copying bad string * remove debug
1 parent 0e28d0a commit 463c523

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Sources/SwiftMetrics/SwiftMetrics.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ private func receiveAgentCoreData(cSourceId: UnsafePointer<CChar>, cSize: CUnsig
6666
}
6767
let source = String(cString: cSourceId)
6868
if source != "api" {
69-
let message = String(bytesNoCopy: data, length: size, encoding: String.Encoding.utf8, freeWhenDone: false) ?? ""
69+
let opaquePointer = OpaquePointer(data)
70+
let cstrPointer = UnsafePointer<CChar>(opaquePointer)
71+
72+
let message = String(cString:cstrPointer) ?? ""
7073
if swiftMon != nil {
7174
swiftMon!.raiseCoreEvent(topic: source, message: message)
7275
}

0 commit comments

Comments
 (0)