1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2025-01-09 20:48:53 +01:00

cppcheck fixes

This commit is contained in:
Anthony Scemama 2022-01-07 11:21:12 +01:00
parent dbb6f78397
commit 3f4b8e2c7e

View File

@ -1,4 +1,5 @@
#+TITLE: Front end API #+TITLE: Front end API
break;
#+PROPERTY: comments org #+PROPERTY: comments org
#+SETUPFILE: ../../docs/theme.setup #+SETUPFILE: ../../docs/theme.setup
# -*- mode: org -*- # -*- mode: org -*-
@ -1723,9 +1724,12 @@ trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_doub
{ {
if (file == NULL) return TREXIO_INVALID_ARG_1; if (file == NULL) return TREXIO_INVALID_ARG_1;
assert(file->back_end < TREXIO_INVALID_BACK_END);
if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS; if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS;
trexio_exit_code rc; trexio_exit_code rc;
int64_t $group_dset_dim$ = 0; int64_t $group_dset_dim$ = 0;
@ -1737,8 +1741,6 @@ trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_doub
uint32_t rank = $group_dset_rank$; uint32_t rank = $group_dset_rank$;
uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$}; uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$};
$group_dset_dtype_double$* $group_dset$_p = ($group_dset_dtype_double$*) $group_dset$;
if ($is_index$) { if ($is_index$) {
/* Handle index type : is_index = $is_index$ */ /* Handle index type : is_index = $is_index$ */
uint64_t dim_size = 1; uint64_t dim_size = 1;
@ -1746,41 +1748,66 @@ trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_doub
dim_size *= dims[i]; dim_size *= dims[i];
} }
$group_dset$_p = CALLOC(dim_size, $group_dset_dtype_double$); $group_dset_dtype_double$* $group_dset$_p =
CALLOC(dim_size, $group_dset_dtype_double$);
if ($group_dset$_p == NULL) return TREXIO_ALLOCATION_FAILED; if ($group_dset$_p == NULL) return TREXIO_ALLOCATION_FAILED;
for (uint64_t i=0; i<dim_size; ++i){ for (uint64_t i=0; i<dim_size; ++i){
$group_dset$_p[i] -= ($group_dset_dtype_double$) 1; $group_dset$_p[i] -= ($group_dset_dtype_double$) 1;
} }
}
assert(file->back_end < TREXIO_INVALID_BACK_END); rc = TREXIO_FAILURE;
switch (file->back_end) {
rc = TREXIO_FAILURE; case TREXIO_TEXT:
switch (file->back_end) { rc = trexio_text_write_$group_dset$(file,
(const $group_dset_dtype_double$*) $group_dset$_p,
case TREXIO_TEXT: rank, dims);
rc = trexio_text_write_$group_dset$(file, $group_dset$_p, rank, dims);
break;
case TREXIO_HDF5:
#ifdef HAVE_HDF5
rc = trexio_hdf5_write_$group_dset$(file, $group_dset$_p, rank, dims);
break;
#else
rc = TREXIO_BACK_END_MISSING;
break;
#endif
/*
case TREXIO_JSON:
rc = trexio_json_write_$group_dset$(file, $group_dset$_p, rank, dims);
break; break;
,*/
}
/* Handle index type */ case TREXIO_HDF5:
if ($is_index$) { #ifdef HAVE_HDF5
FREE($group_dset$_p); rc = trexio_hdf5_write_$group_dset$(file,
(const $group_dset_dtype_double$*) $group_dset$_p,
rank, dims);
break;
#else
rc = TREXIO_BACK_END_MISSING;
break;
#endif
/*
case TREXIO_JSON:
rc = trexio_json_write_$group_dset$(file, $group_dset$_p, rank, dims);
break;
,*/
FREE($group_dset$_p);
}
} else {
rc = TREXIO_FAILURE;
switch (file->back_end) {
case TREXIO_TEXT:
rc = trexio_text_write_$group_dset$(file, $group_dset$, rank, dims);
break;
case TREXIO_HDF5:
#ifdef HAVE_HDF5
rc = trexio_hdf5_write_$group_dset$(file, $group_dset$, rank, dims);
break;
#else
rc = TREXIO_BACK_END_MISSING;
break;
#endif
/*
case TREXIO_JSON:
rc = trexio_json_write_$group_dset$(file, $group_dset$, rank, dims);
break;
,*/
}
} }
return rc; return rc;