Skip to content

Commit fbbce04

Browse files
authored
Avoid using pointer in Ryu (#59743)
1 parent e7b5082 commit fbbce04

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

base/ryu/shortest.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,11 @@ function writeshortest(buf::AbstractVector{UInt8}, pos, x::T,
378378
else
379379
pointoff = olength - abs(nexp)
380380
# shift bytes after pointoff to make room for decchar
381-
ptr = pointer(buf)
382-
memmove(ptr + pos + pointoff, ptr + pos + pointoff - 1, olength - pointoff + 1)
381+
buf_cconv = Base.cconvert(Ptr{UInt8}, buf)
382+
GC.@preserve buf_cconv begin
383+
ptr = Base.unsafe_convert(Ptr{UInt8}, buf_cconv)
384+
memmove(ptr + pos + pointoff, ptr + pos + pointoff - 1, (olength - pointoff + 1)%Csize_t)
385+
end
383386
@inbounds buf[pos + pointoff] = decchar
384387
pos += olength + 1
385388
precision -= olength

0 commit comments

Comments
 (0)