Closed mjacobse closed 2 years ago
Adding an explanation of the non-obvious changes made (see #82 for full discussion):
crow
depends on coptions%array_base
in the non-_coord
casesfptr
and frow
altogether, as they may have to be repointed to fptr_alloc
and frow_alloc
to change C to Fortran indexingcx1
as assumed-size array, because the size is only known from fakeep%n
, which as far as I can tell can only be accessed safely after calling C_F_POINTER
on cakeep
A valid C implementation may return NULL for malloc(0). In that sense, zero-length arrays may be represented by a null pointer in C. When those are passed to the C interface of SSIDS, they are detected as not C_ASSOCIATED, and the corresponding Fortran pointers are nullified. A few of those nullified Fortran pointers are then used illegally without further checks. To fix this, I propose to avoid checking for C_ASSOCIATED altogether by declaring the C arguments as arrays directly.
The problem can be observed for example by setting
in examples/C/ssids.c. A few issues about uninitialized values are reported by valgrind when running the example with these modifications. When additionally setting
options.array_base = 0
, the example segfaults.See #82 for a discussion on a different solution that led to this simplified one.