diff --git a/Package.swift b/Package.swift index 9efba43..b3ade77 100644 --- a/Package.swift +++ b/Package.swift @@ -40,6 +40,7 @@ let package = Package( swiftSettings: [ .enableExperimentalFeature("Lifetimes"), .strictMemorySafety(), + .treatWarning("StrictMemorySafety", as: .error), ] ), .macro( diff --git a/Sources/BinaryParsing/Parser Types/Slicing.swift b/Sources/BinaryParsing/Parser Types/Slicing.swift index 8ab1311..b97d81c 100644 --- a/Sources/BinaryParsing/Parser Types/Slicing.swift +++ b/Sources/BinaryParsing/Parser Types/Slicing.swift @@ -192,7 +192,7 @@ extension ParserSpan { { let rawSpan = try sliceSpan(byteCount: byteCount).bytes do { - let span = Span(_bytes: rawSpan) + let span = unsafe Span(_bytes: rawSpan) return try UTF8Span(validating: span) } catch { throw ParsingError(status: .userError, location: startPosition) diff --git a/Tests/BinaryParsingTests/OptimizationTests.swift b/Tests/BinaryParsingTests/OptimizationTests.swift index 1b0f9d6..d824b2b 100644 --- a/Tests/BinaryParsingTests/OptimizationTests.swift +++ b/Tests/BinaryParsingTests/OptimizationTests.swift @@ -26,10 +26,10 @@ private let data: [UInt8] = [ struct OptimizationTests { func precheckParseFour(parsing input: inout ParserSpan) throws -> Int { try input._checkCount(minimum: 16) - let a = UInt32(_unchecked: (), parsingBigEndian: &input) - let b = UInt32(_unchecked: (), parsingBigEndian: &input) - let c = UInt32(_unchecked: (), parsingBigEndian: &input) - let d = UInt32(_unchecked: (), parsingBigEndian: &input) + let a = unsafe UInt32(_unchecked: (), parsingBigEndian: &input) + let b = unsafe UInt32(_unchecked: (), parsingBigEndian: &input) + let c = unsafe UInt32(_unchecked: (), parsingBigEndian: &input) + let d = unsafe UInt32(_unchecked: (), parsingBigEndian: &input) return Int(a + b + c + d) } diff --git a/Tests/BinaryParsingTests/TestingSupport.swift b/Tests/BinaryParsingTests/TestingSupport.swift index ef7a2ec..fd68fff 100644 --- a/Tests/BinaryParsingTests/TestingSupport.swift +++ b/Tests/BinaryParsingTests/TestingSupport.swift @@ -19,9 +19,9 @@ func === (lhs: borrowing ParserSpan, rhs: borrowing ParserSpan) -> Bool { lhs.count == rhs.count else { return false } - return lhs.withUnsafeBytes { lhs in - rhs.withUnsafeBytes { rhs in - (lhs.baseAddress, lhs.count) == (rhs.baseAddress, rhs.count) + return unsafe lhs.withUnsafeBytes { lhs in + unsafe rhs.withUnsafeBytes { rhs in + unsafe (lhs.baseAddress, lhs.count) == (rhs.baseAddress, rhs.count) } } } @@ -87,7 +87,7 @@ extension Array where Element == UInt8 { if T.isSigned && value < 0 { 0xff } else { 0x00 } } self = - Array(repeating: paddingByte, count: paddingCount) + unsafe Array(repeating: paddingByte, count: paddingCount) + Swift.withUnsafeBytes(of: value.bigEndian, Array.init) } @@ -105,7 +105,7 @@ extension Array where Element == UInt8 { if T.isSigned && value < 0 { 0xff } else { 0x00 } } self = - Swift.withUnsafeBytes(of: value.littleEndian, Array.init) + unsafe Swift.withUnsafeBytes(of: value.littleEndian, Array.init) + Array(repeating: paddingByte, count: paddingCount) } diff --git a/Xcode/Shared.xcconfig b/Xcode/Shared.xcconfig index 173ed92..0a2e61f 100644 --- a/Xcode/Shared.xcconfig +++ b/Xcode/Shared.xcconfig @@ -21,6 +21,10 @@ CODE_SIGN_IDENTITY[sdk=watchos*] = "iOS Developer" CODE_SIGN_IDENTITY[sdk=appletvos*] = "iOS Developer" SWIFT_VERSION = 6 +SWIFT_STRICT_MEMORY_SAFETY = YES +SWIFT_WARNINGS_AS_ERRORS_GROUPS = StrictMemorySafety +SWIFT_STRICT_CONCURRENCY = complete + ONLY_ACTIVE_ARCH[config=Debug] = YES SWIFT_COMPILATION_MODE[config=Release] = wholemodule