diff options
Diffstat (limited to 'src/H5T.c')
-rw-r--r-- | src/H5T.c | 37 |
1 files changed, 22 insertions, 15 deletions
@@ -3623,21 +3623,28 @@ H5T__complete_copy(H5T_t *new_dt, const H5T_t *old_dt, H5T_shared_t *reopened_fo * of each new member with copied values. That is, H5T_copy() is a * deep copy. */ - if (NULL == (new_dt->shared->u.enumer.name = - H5MM_malloc(new_dt->shared->u.enumer.nalloc * sizeof(char *)))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, "enam name array memory allocation failed") - if (NULL == (new_dt->shared->u.enumer.value = - H5MM_malloc(new_dt->shared->u.enumer.nalloc * new_dt->shared->size))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, - "enam value array memory allocation failed") - H5MM_memcpy(new_dt->shared->u.enumer.value, old_dt->shared->u.enumer.value, - new_dt->shared->u.enumer.nmembs * new_dt->shared->size); - for (i = 0; i < new_dt->shared->u.enumer.nmembs; i++) { - if (NULL == (s = H5MM_xstrdup(old_dt->shared->u.enumer.name[i]))) - HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, - "can't copy string for enum value's name") - new_dt->shared->u.enumer.name[i] = s; - } /* end for */ + if (old_dt->shared->u.enumer.nalloc > 0) { + if (NULL == (new_dt->shared->u.enumer.name = + H5MM_malloc(new_dt->shared->u.enumer.nalloc * sizeof(char *)))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, + "enam name array memory allocation failed") + if (NULL == (new_dt->shared->u.enumer.value = + H5MM_malloc(new_dt->shared->u.enumer.nalloc * new_dt->shared->size))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTALLOC, FAIL, + "enam value array memory allocation failed") + H5MM_memcpy(new_dt->shared->u.enumer.value, old_dt->shared->u.enumer.value, + new_dt->shared->u.enumer.nmembs * new_dt->shared->size); + for (i = 0; i < new_dt->shared->u.enumer.nmembs; i++) { + if (NULL == (s = H5MM_xstrdup(old_dt->shared->u.enumer.name[i]))) + HGOTO_ERROR(H5E_DATATYPE, H5E_CANTCOPY, FAIL, + "can't copy string for enum value's name") + new_dt->shared->u.enumer.name[i] = s; + } + } + else { + /* Empty enum */ + HDmemset(&new_dt->shared->u.enumer, 0, sizeof(H5T_enum_t)); + } break; case H5T_VLEN: |