Skip to content

Commit

Permalink
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/crystal/system/unix/getrandom.cr
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ module Crystal::System::Random
if @@getrandom_available
buf = uninitialized UInt8[1]
getrandom(buf.to_slice)
buf.to_unsafe.as(UInt8*).value
buf.unsafe_as(UInt8)
elsif urandom = @@urandom
urandom.read_byte.not_nil!
else
4 changes: 2 additions & 2 deletions src/io/byte_format.cr
Original file line number Diff line number Diff line change
@@ -149,14 +149,14 @@ module IO::ByteFormat
buffer = uninitialized UInt8[{{bytesize}}]
io.read_fully(buffer.to_slice)
buffer.reverse! unless SystemEndian == self
buffer.to_unsafe.as(Pointer({{type.id}})).value
buffer.unsafe_as({{type.id}})
end

def self.decode(type : {{type.id}}.class, bytes : Bytes)
buffer = uninitialized UInt8[{{bytesize}}]
bytes.to_slice[0, {{bytesize}}].copy_to(buffer.to_slice)
buffer.reverse! unless SystemEndian == self
buffer.to_unsafe.as(Pointer({{type.id}})).value
buffer.unsafe_as({{type.id}})
end
{% end %}
end
2 changes: 1 addition & 1 deletion src/random/secure.cr
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ module Random::Secure
end
else
random_bytes(buf.to_slice)
buf.to_unsafe.as({{type}}*).value
buf.unsafe_as({{type}})
end
end
{% end %}

0 comments on commit 32319e3

Please sign in to comment.