This package is using the pointer function in a way that will lead to UB if the compiler gets smarter about memory allocations, or if the garbage collector runs at an unfortunate time.
For example:
|
function nc_inq_grpname(ncid::Integer) |
|
name = zeros(UInt8,NC_MAX_NAME+1) |
|
|
|
check(ccall((:nc_inq_grpname,libnetcdf),Cint,(Cint,Ptr{UInt8}),ncid,name)) |
|
|
|
return unsafe_string(pointer(name)) |
|
end |
The name memory may be freed after the call to pointer and before the call to unsafe_string, resulting in a garbage string being returned.
There are many other similar bugs.
Ideally, the use of the pointer and unsafe_string functions can be replaced with String(view(name,1:findfirst(iszero,name)-1)).
This package is using the
pointerfunction in a way that will lead to UB if the compiler gets smarter about memory allocations, or if the garbage collector runs at an unfortunate time.For example:
NCDatasets.jl/src/netcdf_c.jl
Lines 324 to 330 in 512adb5
The
namememory may be freed after the call topointerand before the call tounsafe_string, resulting in a garbage string being returned.There are many other similar bugs.
Ideally, the use of the
pointerandunsafe_stringfunctions can be replaced withString(view(name,1:findfirst(iszero,name)-1)).