From a295cfe22e821f25601c4e200d4d26c767c996ee Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 29 Mar 2021 01:17:33 +0200 Subject: [PATCH] Compliant with CERT standard --- src/qmckl_ao.org | 4 ++-- src/qmckl_context.org | 17 ++++------------- src/qmckl_error.org | 6 ++---- src/test_qmckl.org | 17 +++++++++-------- 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/qmckl_ao.org b/src/qmckl_ao.org index 6659eef..e26b2d1 100644 --- a/src/qmckl_ao.org +++ b/src/qmckl_ao.org @@ -10,7 +10,7 @@ Gaussian ($p=2$): \[ R_s(\mathbf{r}) = \mathcal{N}_s |\mathbf{r}-\mathbf{R}_A|^{n_s} \sum_{k=1}^{N_{\text{prim}}} a_{ks} - \exp \left( - \gamma_{ks} | \mathbf{r}-\mathbf{R}_A | ^p \right). | + \exp \left( - \gamma_{ks} | \mathbf{r}-\mathbf{R}_A | ^p \right). \] In the case of Gaussian functions, $n_s$ is always zero. @@ -570,7 +570,7 @@ munit_assert_int(0, ==, test_qmckl_ao_polynomial_vgl(context)); | ~context~ | input | Global state | | ~X(3)~ | input | Array containing the coordinates of the points | | ~R(3)~ | input | Array containing the x,y,z coordinates of the center | - | ~n~ | input | Number of computed gaussians | + | ~n~ | input | Number of computed Gaussians | | ~A(n)~ | input | Exponents of the Gaussians | | ~VGL(ldv,5)~ | output | Value, gradients and Laplacian of the Gaussians | | ~ldv~ | input | Leading dimension of array ~VGL~ | diff --git a/src/qmckl_context.org b/src/qmckl_context.org index 6aec0c7..65bfb48 100644 --- a/src/qmckl_context.org +++ b/src/qmckl_context.org @@ -427,9 +427,7 @@ qmckl_context qmckl_context_destroy(const qmckl_context context) { qmckl_exit_code rc; rc = qmckl_context_remove_memory(context,ctx); -/* assert (rc == QMCKL_SUCCESS); - */ ctx->tag = INVALID_TAG; @@ -442,9 +440,6 @@ qmckl_context qmckl_context_destroy(const qmckl_context context) { rc = qmckl_free(context,ctx); assert (rc == QMCKL_SUCCESS); - //memset(ctx, 0, sizeof(qmckl_context_struct)); - - return prev_context; } #+end_src @@ -534,7 +529,7 @@ qmckl_exit_code qmckl_context_append_memory(qmckl_context context, if (alloc == NULL) { ctx->alloc = new_alloc; } else { - while (alloc != NULL) { + while (alloc->next != NULL) { alloc = alloc->next; } alloc->next = new_alloc; @@ -670,8 +665,8 @@ qmckl_context_update_error(qmckl_context context, qmckl_error_struct* error = (qmckl_error_struct*) qmckl_malloc (context, sizeof(qmckl_error_struct)); error->exit_code = exit_code; - strcpy(error->function, function_name); - strcpy(error->message, message); + strncpy(error->function, function_name, QMCKL_MAX_FUN_LEN); + strncpy(error->message, message, QMCKL_MAX_MSG_LEN); ctx->error = error; @@ -797,8 +792,7 @@ if (x < 0) { # -*- org-src-preserve-indentation: t #+begin_src python :var table=table-precision :results drawer :exports result -""" This script generates the C and Fortran constants for the error - codes from the org-mode table. +""" This script generates the C and Fortran constants from the org-mode table. """ result = [ "#+begin_src c :comments org :tangle (eval h)" ] @@ -898,8 +892,6 @@ qmckl_exit_code qmckl_context_update_precision(const qmckl_context context, cons "qmckl_context_update_precision", "ctx->fp"); } - - ctx->fp->precision = QMCKL_DEFAULT_PRECISION; ctx->fp->range = QMCKL_DEFAULT_RANGE; } @@ -1037,7 +1029,6 @@ qmckl_exit_code qmckl_context_update_range(const qmckl_context context, const in } ctx->fp->precision = QMCKL_DEFAULT_PRECISION; - ctx->fp->range = QMCKL_DEFAULT_RANGE; } ctx->fp->range = range; diff --git a/src/qmckl_error.org b/src/qmckl_error.org index 403e22f..1c9f3de 100644 --- a/src/qmckl_error.org +++ b/src/qmckl_error.org @@ -151,7 +151,7 @@ void qmckl_string_of_error(qmckl_exit_code error, char string[<>); break;""" ] return '\n'.join(result) @@ -170,11 +170,9 @@ return '\n'.join(result) # Source #+begin_src c :comments org :tangle (eval c) :noweb yes void qmckl_string_of_error(qmckl_exit_code error, char string[<>]) { - char* message; switch (error) { <> } - strncpy(string,message,<>); } #+end_src diff --git a/src/test_qmckl.org b/src/test_qmckl.org index fe8e3a4..7d4606c 100644 --- a/src/test_qmckl.org +++ b/src/test_qmckl.org @@ -54,7 +54,7 @@ echo "#+begin_src c :tangle no" for file in $files do routine=test_${file%.c} - echo " { (char*) \"${routine}\", ${routine}, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}," + echo " { (const char*) \"${routine}\", ${routine}, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}," done echo "#+end_src" #+end_src @@ -63,11 +63,11 @@ echo "#+end_src" :results: #+NAME: calls #+begin_src c :tangle no - { (char*) "test_qmckl_error", test_qmckl_error, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, - { (char*) "test_qmckl_context", test_qmckl_context, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, - { (char*) "test_qmckl_memory", test_qmckl_memory, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, - { (char*) "test_qmckl_distance", test_qmckl_distance, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, - { (char*) "test_qmckl_ao", test_qmckl_ao, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, + { (const char*) "test_qmckl_error", test_qmckl_error, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, + { (const char*) "test_qmckl_context", test_qmckl_context, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, + { (const char*) "test_qmckl_memory", test_qmckl_memory, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, + { (const char*) "test_qmckl_distance", test_qmckl_distance, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, + { (const char*) "test_qmckl_ao", test_qmckl_ao, NULL,NULL,MUNIT_TEST_OPTION_NONE,NULL}, #+end_src :end: @@ -91,12 +91,13 @@ int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) { static const MunitSuite test_suite = { - (char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE + (const char*) "", test_suite_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }; - int result = munit_suite_main(&test_suite, (void*) "µnit", argc, argv); + int result = munit_suite_main(&test_suite, (const void*) "µnit", argc, argv); muntrace(); return result; } #+end_src +