Skip to content

Commit 2a3b237

Browse files
committed
[swift-reflection-test] Strings read here are not always valid UTF-8.
The “string length” primitive was validating the string data as valid UTF-8 to get the length. However, mangled names, which get read by this operation, are not always valid UTF-8. Just count the bytes until a ‘0’ and don’t validate.
1 parent 21e5a7e commit 2a3b237

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ internal func sendStringLength() {
271271
debugLog("BEGIN \(#function)"); defer { debugLog("END \(#function)") }
272272
let address = readUInt()
273273
let cString = UnsafePointer<CChar>(bitPattern: address)!
274-
let count = String(validatingUTF8: cString)!.utf8.count
274+
var count = 0
275+
while cString[count] != CChar(0) {
276+
count = count + 1
277+
}
275278
sendValue(count)
276279
}
277280

0 commit comments

Comments
 (0)