Skip to content

Commit 57e8206

Browse files
committed
Final robust byte-level encoding for RPC strings to eliminate memory leaks and alignment issues
1 parent cc8640e commit 57e8206

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

Sources/CosmoMSSQL/TDS/TDSRPCRequest.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ struct TDSRPCRequest {
192192
buf.writeInteger(UInt64(byteLen), endianness: .little)
193193
buf.writeInteger(UInt32(byteLen), endianness: .little)
194194
for unit in utf16 {
195-
buf.writeInteger(unit, endianness: .little)
195+
buf.writeInteger(UInt8(unit & 0xFF))
196+
buf.writeInteger(UInt8((unit >> 8) & 0xFF))
196197
}
197198
buf.writeInteger(UInt32(0), endianness: .little)
198199
}
@@ -215,7 +216,8 @@ struct TDSRPCRequest {
215216
let utf16 = Array(s.utf16)
216217
buf.writeInteger(UInt8(utf16.count))
217218
for unit in utf16 {
218-
buf.writeInteger(unit, endianness: .little)
219+
buf.writeInteger(UInt8(unit & 0xFF))
220+
buf.writeInteger(UInt8((unit >> 8) & 0xFF))
219221
}
220222
}
221223

0 commit comments

Comments
 (0)