From 86a92f2494f0feed57d8366d26ab03b690c01925 Mon Sep 17 00:00:00 2001 From: v1j4y Date: Sun, 9 Oct 2022 00:03:45 +0200 Subject: [PATCH] Added size_max for set determinant. --- org/qmckl_determinant.org | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/org/qmckl_determinant.org b/org/qmckl_determinant.org index 78d54f1..3f03803 100644 --- a/org/qmckl_determinant.org +++ b/org/qmckl_determinant.org @@ -331,8 +331,8 @@ int64_t* qmckl_get_determinant_mo_index_beta (const qmckl_context context) { qmckl_exit_code qmckl_set_determinant_type (const qmckl_context context, const char t); qmckl_exit_code qmckl_set_determinant_det_num_alpha (const qmckl_context context, const int64_t det_num_alpha); qmckl_exit_code qmckl_set_determinant_det_num_beta (const qmckl_context context, const int64_t det_num_beta); -qmckl_exit_code qmckl_set_determinant_mo_index_alpha (const qmckl_context context, const int64_t* mo_index_alpha); -qmckl_exit_code qmckl_set_determinant_mo_index_beta (const qmckl_context context, const int64_t* mo_index_beta); +qmckl_exit_code qmckl_set_determinant_mo_index_alpha (const qmckl_context context, const int64_t* mo_index_alpha, const int64_t size_max); +qmckl_exit_code qmckl_set_determinant_mo_index_beta (const qmckl_context context, const int64_t* mo_index_beta, const int64_t size_max); #+end_src #+NAME:pre2 @@ -405,7 +405,7 @@ qmckl_exit_code qmckl_set_determinant_det_num_beta(qmckl_context context, const <> } -qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, const int64_t* mo_index_alpha) { +qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, const int64_t* mo_index_alpha, const int64_t size_max) { <> int32_t mask = 1 << 3; @@ -430,6 +430,13 @@ qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, con NULL); } + if (size_max * sizeof(int64_t) < mem_info.size) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_3, + "qmckl_set_determinant_mo_index_alpha", + "input array too small"); + } + memcpy(new_array, mo_index_alpha, mem_info.size); ctx->det.mo_index_alpha = new_array; @@ -437,7 +444,7 @@ qmckl_exit_code qmckl_set_determinant_mo_index_alpha(qmckl_context context, con <> } -qmckl_exit_code qmckl_set_determinant_mo_index_beta(qmckl_context context, const int64_t* mo_index_beta) { +qmckl_exit_code qmckl_set_determinant_mo_index_beta(qmckl_context context, const int64_t* mo_index_beta, const int64_t size_max) { <> int32_t mask = 1 << 4; @@ -462,6 +469,13 @@ qmckl_exit_code qmckl_set_determinant_mo_index_beta(qmckl_context context, cons NULL); } + if (size_max * sizeof(int64_t) < mem_info.size) { + return qmckl_failwith( context, + QMCKL_INVALID_ARG_3, + "qmckl_set_determinant_mo_index_beta", + "input array too small"); + } + memcpy(new_array, mo_index_beta, mem_info.size); ctx->det.mo_index_beta = new_array;