1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

apply some suggestions from cppcheck

This commit is contained in:
q-posev 2021-09-12 13:25:03 +02:00
parent 97f1d3b723
commit 12dd1fd8dc
3 changed files with 14 additions and 7 deletions

View File

@ -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); char* tmp_str = CALLOC(dims[0]*(max_str_len+1), char);
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED; if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
char** dset_str = CALLOC(dims[0], char*); 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; char* pch;
size_t pch_len;
/* parse the string using strtok */ /* parse the string using strtok */
for(uint64_t i=0; i<dims[0]; i++) { 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; return TREXIO_FAILURE;
} }
pch_len = strlen(pch) + 1; size_t pch_len = strlen(pch) + 1;
if (pch_len > max_str_len) { if (pch_len > max_str_len) {
FREE(dset_str[0]); FREE(dset_str[0]);

View File

@ -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 */ /* we are going to write variable-length strings */
hid_t memtype = H5Tcopy (H5T_C_S1); hid_t memtype = H5Tcopy (H5T_C_S1);
if (memtype <= 0) return TREXIO_INVALID_ID;
status = H5Tset_size (memtype, H5T_VARIABLE); status = H5Tset_size (memtype, H5T_VARIABLE);
if (status < 0) return TREXIO_FAILURE;
if ( H5LTfind_dataset(f->$group$_group, $GROUP_DSET$_NAME) != 1 ) { if ( H5LTfind_dataset(f->$group$_group, $GROUP_DSET$_NAME) != 1 ) {
/* code to create dataset */ /* code to create dataset */
hid_t filetype = H5Tcopy (H5T_FORTRAN_S1); hid_t filetype = H5Tcopy (H5T_FORTRAN_S1);
if (filetype <= 0) return TREXIO_INVALID_ID;
status = H5Tset_size (filetype, H5T_VARIABLE); status = H5Tset_size (filetype, H5T_VARIABLE);
if (status < 0) return TREXIO_FAILURE;
hid_t dspace = H5Screate_simple( (int) rank, (const hsize_t*) dims, NULL); 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, dset_id = H5Dcreate (f->$group$_group, $GROUP_DSET$_NAME, filetype, dspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);

View File

@ -484,7 +484,6 @@ trexio_text_read_$group$ (trexio_text_t* const file)
char* tmp_$group_dset$; char* tmp_$group_dset$;
if(size_$group_dset$ != 0) tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char); 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) { for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
$group$->$group_dset$[i] = tmp_$group_dset$; $group$->$group_dset$[i] = tmp_$group_dset$;
/* conventional fcanf with "%s" only return the string before the first space character /* 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; 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; tmp_$group_dset$ += tmp_$group_dset$_len + 1;
} }
// END REPEAT GROUP_DSET_STR // 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); char* tmp_str = CALLOC(dims[0]*32 + 1, char);
if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED; if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
size_t tmp_len = 0;
for (uint64_t i=0 ; i<dims[0] ; ++i) { 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; $group$->$group_dset$[i] = tmp_str;
strncpy(tmp_str, dset[i], tmp_len); strncpy(tmp_str, dset[i], tmp_len);
tmp_str += tmp_len + 1; tmp_str += tmp_len + 1;