From bdf770d61721879d54914803dd761dcc995d913c Mon Sep 17 00:00:00 2001 From: q-posev Date: Wed, 28 Sep 2022 12:48:18 +0200 Subject: [PATCH] Fix Python tests and static checker warnings --- python/test/test_api.py | 6 +----- src/templates_front/templator_front.org | 4 ++-- src/templates_text/templator_text.org | 20 ++++++++++---------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/python/test/test_api.py b/python/test/test_api.py index 342a528..4dff3f6 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -182,15 +182,11 @@ class TestIO: assert int_num == int64_num # write the data for the ground state offset = 0 + trexio.write_state_id(self.test_file, 0) trexio.write_determinant_list(self.test_file, offset, det_num, dets) assert trexio.has_determinant_list(self.test_file) trexio.write_determinant_coefficient(self.test_file, offset, det_num, coeffs) assert trexio.has_determinant_coefficient(self.test_file) - # write the data for some other state - self.test_file.set_state(2) - trexio.write_determinant_coefficient(self.test_file, offset, det_num, coeffs_s2) - assert trexio.has_determinant_coefficient(self.test_file) - self.test_file.set_state(0) # manually check the consistency between coefficient_size and number of determinants assert trexio.read_determinant_coefficient_size(self.test_file) == trexio.read_determinant_num(self.test_file) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index d04fa10..308b977 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -3178,7 +3178,7 @@ trexio_read_$group_dset$(trexio_t* const file, /* Find the maximal value along all dimensions to define the compression technique in the back end */ int64_t max_dim = unique_dims[0]; if (unique_rank != 1) { - for (int i = 1; i < unique_rank; i++) { + for (uint32_t i = 1; i < unique_rank; i++) { if (unique_dims[i] > max_dim) max_dim = unique_dims[i]; } } @@ -3310,7 +3310,7 @@ trexio_write_$group_dset$(trexio_t* const file, /* Find the maximal value along all dimensions to define the compression technique in the back end */ int64_t max_dim = unique_dims[0]; if (unique_rank != 1) { - for (int i = 1; i < unique_rank; i++) { + for (uint32_t i = 1; i < unique_rank; i++) { if (unique_dims[i] > max_dim) max_dim = unique_dims[i]; } } diff --git a/src/templates_text/templator_text.org b/src/templates_text/templator_text.org index 99ff8a2..9ed7858 100644 --- a/src/templates_text/templator_text.org +++ b/src/templates_text/templator_text.org @@ -1364,9 +1364,9 @@ trexio_exit_code trexio_text_read_$group_dset$(trexio_t* const file, /* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */ char file_full_path[TREXIO_MAX_FILENAME_LENGTH]; /* Copy directory name in file_full_path */ - strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); + strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH); /* Append name of the file with sparse data */ - strncat (file_full_path, file_name, sizeof(file_name)); + strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); /* Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads */ FILE* f = fopen(file_full_path, "r"); @@ -1426,9 +1426,9 @@ trexio_text_read_$group_dset$_size(trexio_t* const file, int64_t* const size_max /* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */ char file_full_path[TREXIO_MAX_FILENAME_LENGTH]; /* Copy directory name in file_full_path */ - strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); + strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH); /* Append name of the file with sparse data */ - strncat (file_full_path, file_name, sizeof(file_name)); + strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); /* Open the file in "r" (read) mode to guarantee that no truncation happens upon consecutive reads */ FILE* f = fopen(file_full_path, "r"); @@ -1476,9 +1476,9 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file, /* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */ char file_full_path[TREXIO_MAX_FILENAME_LENGTH]; /* Copy directory name in file_full_path */ - strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name) - append_str_len); + strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH); /* Append name of the file with sparse data */ - strncat (file_full_path, file_name, sizeof(file_name)); + strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); /* Open the file in "a" (append) mode to guarantee that no truncation happens upon consecutive writes */ FILE* f = fopen(file_full_path, "a"); @@ -1523,9 +1523,9 @@ trexio_exit_code trexio_text_write_$group_dset$(trexio_t* const file, memset (file_full_path, 0, TREXIO_MAX_FILENAME_LENGTH); /* Copy directory name in file_full_path */ - strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(group_file_name)); + strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH); /* Append name of the file with sparse data */ - strncat (file_full_path, group_file_name, sizeof(group_file_name)); + strncat (file_full_path, group_file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(group_file_name)); bool file_exists = trexio_text_file_exists(file_full_path); @@ -1551,9 +1551,9 @@ trexio_exit_code trexio_text_has_$group_dset$(trexio_t* const file) /* The full path to the destination TXT file with sparse data. This will include TREXIO directory name. */ char file_full_path[TREXIO_MAX_FILENAME_LENGTH]; /* Copy directory name in file_full_path */ - strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); + strncpy (file_full_path, file->file_name, TREXIO_MAX_FILENAME_LENGTH); /* Append name of the file with sparse data */ - strncat (file_full_path, file_name, sizeof(file_name)); + strncat (file_full_path, file_name, TREXIO_MAX_FILENAME_LENGTH - sizeof(file_name)); /* Check the return code of access function to determine whether the file with data exists or not */ if (access(file_full_path, F_OK) == 0){