From 463c5235f78fc6444b24e0d458f6d8e02af79f60 Mon Sep 17 00:00:00 2001 From: Sian January Date: Mon, 22 May 2017 12:27:25 +0100 Subject: [PATCH] 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 --- Sources/SwiftMetrics/SwiftMetrics.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/SwiftMetrics/SwiftMetrics.swift b/Sources/SwiftMetrics/SwiftMetrics.swift index 764a0cc..68259fc 100644 --- a/Sources/SwiftMetrics/SwiftMetrics.swift +++ b/Sources/SwiftMetrics/SwiftMetrics.swift @@ -66,7 +66,10 @@ private func receiveAgentCoreData(cSourceId: UnsafePointer, cSize: CUnsig } let source = String(cString: cSourceId) if source != "api" { - let message = String(bytesNoCopy: data, length: size, encoding: String.Encoding.utf8, freeWhenDone: false) ?? "" + let opaquePointer = OpaquePointer(data) + let cstrPointer = UnsafePointer(opaquePointer) + + let message = String(cString:cstrPointer) ?? "" if swiftMon != nil { swiftMon!.raiseCoreEvent(topic: source, message: message) }