diff --git a/src/imas_mex_casts.c b/src/imas_mex_casts.c index d2e997f..eaaf2db 100644 --- a/src/imas_mex_casts.c +++ b/src/imas_mex_casts.c @@ -274,6 +274,11 @@ al_status_t castCellToChar(mxArray ** data) numel = mxGetNumberOfElements(cellData); + if (numel == 0) { + *data = NULL; + return status; + } + strings = malloc(numel*sizeof(char *)); for (i = 0; i < numel; i++) { cell = mxGetCell(*data, (mwIndex) i); diff --git a/src/imas_mex_utils.c b/src/imas_mex_utils.c index 3f63550..ceaecc9 100644 --- a/src/imas_mex_utils.c +++ b/src/imas_mex_utils.c @@ -975,6 +975,7 @@ al_status_t my_al_write_data(struct imas_mex_actionInfo * action, struct imas_me if (field->datatype == CHAR_DATA && field->dim == 2) { if (mxIsCell(data)) { if (status.code >= 0) status = cast_status = castCellToChar((mxArray **) &data); + if (data == NULL) return (al_status_t) {0,""}; } }