Skip to content

Commit a271eb2

Browse files
authored
Merge pull request #85544 from tbkka/tbkka-Issue85539
Properly initialize buffer when called via legacy ABI
2 parents 79c234b + f653585 commit a271eb2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stdlib/public/core/FloatingPointToString.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ public func _float16ToStringImpl(
157157
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
158158
_unchecked: textBuffer,
159159
count: Int(bufferLength))
160+
for i in 0..<Int(bufferLength) {
161+
buffer[unchecked: i] = 0x30
162+
}
160163
let textRange = _Float16ToASCII(value: value, buffer: &buffer)
161164
let textLength = textRange.upperBound - textRange.lowerBound
162165

@@ -446,6 +449,9 @@ internal func _float32ToStringImpl(
446449
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
447450
_unchecked: textBuffer,
448451
count: Int(bufferLength))
452+
for i in 0..<Int(bufferLength) {
453+
buffer[unchecked: i] = 0x30
454+
}
449455
let textRange = _Float32ToASCII(value: value, buffer: &buffer)
450456
let textLength = textRange.upperBound - textRange.lowerBound
451457

@@ -694,6 +700,9 @@ internal func _float64ToStringImpl(
694700
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
695701
_unchecked: textBuffer,
696702
count: Int(bufferLength))
703+
for i in 0..<Int(bufferLength) {
704+
buffer[unchecked: i] = 0x30
705+
}
697706
let textRange = _Float64ToASCII(value: value, buffer: &buffer)
698707
let textLength = textRange.upperBound - textRange.lowerBound
699708

@@ -1197,6 +1206,9 @@ internal func _float80ToStringImpl(
11971206
var buffer = unsafe MutableSpan<UTF8.CodeUnit>(
11981207
_unchecked: textBuffer,
11991208
count: Int(bufferLength))
1209+
for i in 0..<Int(bufferLength) {
1210+
buffer[unchecked: i] = 0x30
1211+
}
12001212
let textRange = _Float80ToASCII(value: value, buffer: &buffer)
12011213
let textLength = textRange.upperBound - textRange.lowerBound
12021214

0 commit comments

Comments
 (0)