Doesn’t that push the string contents out-of-bounds? Because the base address has been moved up, the deferred-length string pointer is supposed to become shorter (elem_len
is what len(stream)
should return in Fortran).
Edit: I should probably check what istat
says. I wrote some helper functions a while ago, but didn’t have time to include them here yet:
static const char *cfi_errstrs[12] = {
"No error detected.\n",
"The base address member of a C descriptor is a null pointer in a context that requires a non-null pointer value.\n",
"The base address member of a C descriptor is not a null pointer in a context that requires a null pointer value.\n",
"The value supplied for the element length member of a C descriptor is not valid.\n",
"The value supplied for the rank member of a C descriptor is not valid.\n",
"The value supplied for the type member of a C descriptor is not valid.\n",
"The value supplied for the attribute member of a C descriptor is not valid.\n",
"The value supplied for the extent member of a CFI_dim_t structure is not valid.\n",
"A C descriptor is invalid in some way.\n",
"Memory allocation failed.\n",
"A reference is out of bounds.\n",
"Unrecognized status code.\n"
};
// Returns the description string for an error code.
//
const char* cfiGetErrorString(int stat) {
switch (stat) {
case CFI_SUCCESS: return cfi_errstrs[0] ; break;
case CFI_ERROR_BASE_ADDR_NULL: return cfi_errstrs[1] ; break;
case CFI_ERROR_BASE_ADDR_NOT_NULL: return cfi_errstrs[2] ; break;
case CFI_INVALID_ELEM_LEN: return cfi_errstrs[3] ; break;
case CFI_INVALID_RANK: return cfi_errstrs[4] ; break;
case CFI_INVALID_TYPE: return cfi_errstrs[5] ; break;
case CFI_INVALID_ATTRIBUTE: return cfi_errstrs[6] ; break;
case CFI_INVALID_EXTENT: return cfi_errstrs[7] ; break;
case CFI_INVALID_DESCRIPTOR: return cfi_errstrs[8] ; break;
case CFI_ERROR_MEM_ALLOCATION: return cfi_errstrs[9] ; break;
case CFI_ERROR_OUT_OF_BOUNDS: return cfi_errstrs[10] ; break;
}
return cfi_errstrs[11];
}
#define CHECK_CFI(func) \
{ \
int stat = (func); \
if (stat != CFI_SUCCESS) { \
fprintf(stderr,"%s:%d: CFI API failed with error: (%d) %s", \
__FILE__, __LINE__, stat, cfiGetErrorString(stat)); \
} \
}