Skip to content

Use of pointer function #297

Description

@nhz2

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)).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions