From 3f4b8e2c7ec2baa3cb56766bb20f61e307b94a21 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 7 Jan 2022 11:21:12 +0100 Subject: [PATCH] cppcheck fixes --- src/templates_front/templator_front.org | 83 ++++++++++++++++--------- 1 file changed, 55 insertions(+), 28 deletions(-) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index aaaa51b..d78efa6 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -1,4 +1,5 @@ #+TITLE: Front end API +break; #+PROPERTY: comments org #+SETUPFILE: ../../docs/theme.setup # -*- 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; + assert(file->back_end < TREXIO_INVALID_BACK_END); + if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2; if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS; + trexio_exit_code rc; 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$; 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$) { /* Handle index type : is_index = $is_index$ */ 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]; } - $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; for (uint64_t i=0; iback_end < TREXIO_INVALID_BACK_END); + rc = TREXIO_FAILURE; + switch (file->back_end) { - rc = TREXIO_FAILURE; - switch (file->back_end) { - - case TREXIO_TEXT: - 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); + case TREXIO_TEXT: + rc = trexio_text_write_$group_dset$(file, + (const $group_dset_dtype_double$*) $group_dset$_p, + rank, dims); break; - ,*/ - } - /* Handle index type */ - if ($is_index$) { - FREE($group_dset$_p); + case TREXIO_HDF5: +#ifdef HAVE_HDF5 + 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;