mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-08-25 06:31:43 +02:00
apply some suggestions from cppcheck
This commit is contained in:
parent
97f1d3b723
commit
12dd1fd8dc
@ -2387,10 +2387,12 @@ trexio_write_$group_dset$_low (trexio_t* const file, const char* dset_in, const
|
||||
char* tmp_str = CALLOC(dims[0]*(max_str_len+1), char);
|
||||
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
|
||||
char** dset_str = CALLOC(dims[0], char*);
|
||||
if (dset_str == NULL) return TREXIO_ALLOCATION_FAILED;
|
||||
if (dset_str == NULL) {
|
||||
FREE(tmp_str);
|
||||
return TREXIO_ALLOCATION_FAILED;
|
||||
}
|
||||
|
||||
char* pch;
|
||||
size_t pch_len;
|
||||
/* parse the string using strtok */
|
||||
for(uint64_t i=0; i<dims[0]; i++) {
|
||||
|
||||
@ -2402,7 +2404,7 @@ trexio_write_$group_dset$_low (trexio_t* const file, const char* dset_in, const
|
||||
return TREXIO_FAILURE;
|
||||
}
|
||||
|
||||
pch_len = strlen(pch) + 1;
|
||||
size_t pch_len = strlen(pch) + 1;
|
||||
|
||||
if (pch_len > max_str_len) {
|
||||
FREE(dset_str[0]);
|
||||
|
@ -536,15 +536,22 @@ trexio_hdf5_write_$group_dset$ (trexio_t* const file, const char** $group_dset$,
|
||||
|
||||
/* we are going to write variable-length strings */
|
||||
hid_t memtype = H5Tcopy (H5T_C_S1);
|
||||
if (memtype <= 0) return TREXIO_INVALID_ID;
|
||||
|
||||
status = H5Tset_size (memtype, H5T_VARIABLE);
|
||||
if (status < 0) return TREXIO_FAILURE;
|
||||
|
||||
if ( H5LTfind_dataset(f->$group$_group, $GROUP_DSET$_NAME) != 1 ) {
|
||||
|
||||
/* code to create dataset */
|
||||
hid_t filetype = H5Tcopy (H5T_FORTRAN_S1);
|
||||
if (filetype <= 0) return TREXIO_INVALID_ID;
|
||||
|
||||
status = H5Tset_size (filetype, H5T_VARIABLE);
|
||||
if (status < 0) return TREXIO_FAILURE;
|
||||
|
||||
hid_t dspace = H5Screate_simple( (int) rank, (const hsize_t*) dims, NULL);
|
||||
if (dspace <= 0) return TREXIO_INVALID_ID;
|
||||
|
||||
dset_id = H5Dcreate (f->$group$_group, $GROUP_DSET$_NAME, filetype, dspace,
|
||||
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
@ -484,7 +484,6 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
||||
char* tmp_$group_dset$;
|
||||
if(size_$group_dset$ != 0) tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char);
|
||||
|
||||
size_t tmp_$group_dset$_len = 0;
|
||||
for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
|
||||
$group$->$group_dset$[i] = tmp_$group_dset$;
|
||||
/* conventional fcanf with "%s" only return the string before the first space character
|
||||
@ -500,7 +499,7 @@ trexio_text_read_$group$ (trexio_text_t* const file)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tmp_$group_dset$_len = strlen($group$->$group_dset$[i]);
|
||||
size_t tmp_$group_dset$_len = strlen($group$->$group_dset$[i]);
|
||||
tmp_$group_dset$ += tmp_$group_dset$_len + 1;
|
||||
}
|
||||
// END REPEAT GROUP_DSET_STR
|
||||
@ -851,9 +850,8 @@ trexio_text_write_$group_dset$ (trexio_t* const file, const char** dset, const u
|
||||
char* tmp_str = CALLOC(dims[0]*32 + 1, char);
|
||||
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
|
||||
|
||||
size_t tmp_len = 0;
|
||||
for (uint64_t i=0 ; i<dims[0] ; ++i) {
|
||||
tmp_len = strlen(dset[i]);
|
||||
size_t tmp_len = strlen(dset[i]);
|
||||
$group$->$group_dset$[i] = tmp_str;
|
||||
strncpy(tmp_str, dset[i], tmp_len);
|
||||
tmp_str += tmp_len + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user