Skip to content

Commit 0af2050

Browse files
KenoKristofferC
authored andcommitted
Check return value of SystemFunction036 (#34429)
In both places we call it. Also tabs-to-spaces for the new code to match the formatting of the rest of the code.
1 parent 1b0e987 commit 0af2050

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

base/file.jl

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,18 @@ end
519519

520520
# generate a random string from random bytes
521521
function _rand_string()
522-
nchars = 10
523-
A = Vector{UInt8}(undef, nchars)
524-
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Cvoid}, UInt32), A, sizeof(A))
525-
526-
slug = Base.StringVector(10)
527-
chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
528-
for i = 1:nchars
529-
slug[i] = chars[(A[i] % length(chars)) + 1]
530-
end
531-
return name = String(slug)
522+
nchars = 10
523+
A = Vector{UInt8}(undef, nchars)
524+
windowserror("SystemFunction036 (RtlGenRandom)", 0 == ccall(
525+
(:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Cvoid}, UInt32),
526+
A, sizeof(A)))
527+
528+
slug = Base.StringVector(10)
529+
chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
530+
for i = 1:nchars
531+
slug[i] = chars[(A[i] % length(chars)) + 1]
532+
end
533+
return name = String(slug)
532534
end
533535

534536
function tempname(parent::AbstractString=tempdir(); cleanup::Bool=true)

stdlib/Random/src/RNGs.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ end # os-test
4343
for T in (Bool, BitInteger_types...)
4444
if Sys.iswindows()
4545
@eval function rand!(rd::RandomDevice, A::Array{$T}, ::SamplerType{$T})
46-
ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Cvoid}, UInt32),
47-
A, sizeof(A))
46+
Base.windowserror("SystemFunction036 (RtlGenRandom)", 0 == ccall(
47+
(:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Cvoid}, UInt32),
48+
A, sizeof(A)))
4849
A
4950
end
5051
else

0 commit comments

Comments
 (0)