1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-10-02 14:31:05 +02:00

pass max_str_len parameter also to read group_str

This commit is contained in:
q-posev 2021-06-14 14:36:19 +02:00
parent be66feec16
commit ae32a02652
3 changed files with 11 additions and 22 deletions

View File

@ -1611,10 +1611,10 @@ trexio_write_$group_dset$ (trexio_t* const file, const char* dset, const uint32_
if (pch_len > max_str_len) {
FREE(dset_str[0]);
FREE(dset_str);
return TREXIO_INVALID_ARG_3;
return TREXIO_INVALID_STR_LEN;
}
dset_str[i]=tmp_str;
dset_str[i] = tmp_str;
strncpy(tmp_str, pch, pch_len);
tmp_str += pch_len + 1;
}
@ -1741,11 +1741,11 @@ trexio_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t m
switch (file->back_end) {
case TREXIO_TEXT:
rc = trexio_text_read_$group_str$(file, str);
return trexio_text_read_$group_str$(file, str, max_str_len);
break;
case TREXIO_HDF5:
rc = trexio_hdf5_read_$group_str$(file, str);
return trexio_hdf5_read_$group_str$(file, str, max_str_len);
break;
/*
case TREXIO_JSON:
@ -1754,16 +1754,6 @@ trexio_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t m
,*/
}
if (rc != TREXIO_SUCCESS) return rc;
size_t len_read = strlen(str);
if (max_str_len < len_read) {
for(size_t i=max_str_len; i<len_read; i++) {
str[i] = '\0';
}
}
return TREXIO_SUCCESS;
}
#+end_src
@ -1778,7 +1768,7 @@ trexio_write_$group_str$ (trexio_t* const file, const char* str, const uint32_t
if (trexio_has_$group_str$(file) == TREXIO_SUCCESS) return TREXIO_NUM_ALREADY_EXISTS;
size_t len_write = strlen(str);
if (max_str_len < len_write) return TREXIO_INVALID_ARG_3;
if (max_str_len < len_write) return TREXIO_INVALID_STR_LEN;
switch (file->back_end) {
@ -1796,7 +1786,6 @@ trexio_write_$group_str$ (trexio_t* const file, const char* str, const uint32_t
,*/
}
return TREXIO_FAILURE;
}
#+end_src

View File

@ -619,14 +619,14 @@ trexio_hdf5_has_$group_dset$ (trexio_t* const file)
#+begin_src c :tangle hrw_attr_str_hdf5.h :exports none
trexio_exit_code trexio_hdf5_has_$group_str$ (trexio_t* const file);
trexio_exit_code trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str);
trexio_exit_code trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len);
trexio_exit_code trexio_hdf5_write_$group_str$(trexio_t* const file, const char* str);
#+end_src
#+begin_src c :tangle read_attr_str_hdf5.c
trexio_exit_code
trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str)
trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -650,7 +650,7 @@ trexio_hdf5_read_$group_str$ (trexio_t* const file, char* const str)
if (mem_id <= 0) return TREXIO_INVALID_ID;
herr_t status;
status = H5Tset_size(mem_id, sdim);
status = (max_str_len+1) > sdim ? H5Tset_size(mem_id, sdim) : H5Tset_size(mem_id, max_str_len+1) ;
if (status < 0) return TREXIO_FAILURE;
status = H5Aread(str_id, mem_id, str);

View File

@ -889,13 +889,13 @@ trexio_text_has_$group_dset$ (trexio_t* const file)
#+begin_src c :tangle hrw_attr_str_text.h :exports none
trexio_exit_code trexio_text_has_$group_str$ (trexio_t* const file);
trexio_exit_code trexio_text_read_$group_str$ (trexio_t* const file, char* const str);
trexio_exit_code trexio_text_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len);
trexio_exit_code trexio_text_write_$group_str$ (trexio_t* const file, const char* str);
#+end_src
#+begin_src c :tangle read_attr_str_text.c
trexio_exit_code
trexio_text_read_$group_str$ (trexio_t* const file, char* const str)
trexio_text_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len)
{
if (file == NULL) return TREXIO_INVALID_ARG_1;
@ -904,7 +904,7 @@ trexio_text_read_$group_str$ (trexio_t* const file, char* const str)
$group$_t* const $group$ = trexio_text_read_$group$((trexio_text_t*) file);
if ($group$ == NULL) return TREXIO_FAILURE;
strcpy(str, $group$->$group_str$);
strncpy(str, $group$->$group_str$, max_str_len);
return TREXIO_SUCCESS;