# Internal I/O with stream access?

**URL:** <https://fortran-lang.discourse.group/t/internal-i-o-with-stream-access/8439>\
**Category:** Help\
**Created:** [August 5, 2024, 8:29pm UTC](https://fortran-lang.discourse.group/t/internal-i-o-with-stream-access/8439 "2024-08-05T20:29:57Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [August 7, 2024, 12:51pm UTC](https://fortran-lang.discourse.group/t/internal-i-o-with-stream-access/8439/7 "2024-08-07T12:51:16Z")

</div>

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](https://fortran-lang.discourse.group/t/return-an-array-of-strings-from-fortran-to-c/5100/15), but didn’t have time to include them here yet:

```auto
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)); \
    } \
}

```

---

_[View the full topic](https://fortran-lang.discourse.group/t/internal-i-o-with-stream-access/8439)._
