Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace calls to StaticArray(UInt8, 1)#unsafe_as(UInt8) #14685

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/crystal/system/unix/getrandom.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ module Crystal::System::Random
init unless @@initialized

if @@getrandom_available
buf = uninitialized UInt8[1]
getrandom(buf.to_slice)
buf.unsafe_as(UInt8)
buf = uninitialized UInt8
getrandom(pointerof(buf).to_slice(1))
buf
elsif urandom = @@urandom
urandom.read_byte.not_nil!
else
Expand Down
6 changes: 3 additions & 3 deletions src/crystal/system/wasi/random.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ module Crystal::System::Random
end

def self.next_u : UInt8
buf = uninitialized UInt8[1]
random_bytes(buf.to_slice)
buf.unsafe_as(UInt8)
buf = uninitialized UInt8
random_bytes(pointerof(buf).to_slice(1))
buf
end
end
6 changes: 3 additions & 3 deletions src/crystal/system/win32/random.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Crystal::System::Random
end

def self.next_u : UInt8
buf = uninitialized UInt8[1]
random_bytes(buf.to_slice)
buf.unsafe_as(UInt8)
buf = uninitialized UInt8
random_bytes(pointerof(buf).to_slice(1))
buf
end
end
Loading