From 13efdcb0107539b016545bfad8b3eb3be0e988ab Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Mon, 14 Aug 2023 15:52:53 -0700 Subject: [PATCH 1/3] Add const to arguments Reported by: cppcheck-2.11 --- libcperciva/POSIX/posix-restrict.c | 2 +- libcperciva/crypto/crypto_entropy.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libcperciva/POSIX/posix-restrict.c b/libcperciva/POSIX/posix-restrict.c index cad3e8f9..f158333e 100644 --- a/libcperciva/POSIX/posix-restrict.c +++ b/libcperciva/POSIX/posix-restrict.c @@ -1,5 +1,5 @@ static int -foo(char * restrict x, char * restrict y) +foo(const char * restrict x, const char * restrict y) { return (x == y); diff --git a/libcperciva/crypto/crypto_entropy.c b/libcperciva/crypto/crypto_entropy.c index 44c7117d..c9023c2c 100644 --- a/libcperciva/crypto/crypto_entropy.c +++ b/libcperciva/crypto/crypto_entropy.c @@ -35,7 +35,7 @@ static int instantiated = 0; #define GENERATE_MAXLEN 65536 static int instantiate(void); -static void update(uint8_t *, size_t); +static void update(const uint8_t *, size_t); static int reseed(void); static void generate(uint8_t *, size_t); @@ -93,7 +93,7 @@ instantiate(void) * Update the DRBG state using the provided data. (Section 10.1.2.2) */ static void -update(uint8_t * data, size_t datalen) +update(const uint8_t * data, size_t datalen) { HMAC_SHA256_CTX ctx; uint8_t K[32]; From 566a86046af35f48026eb06fea0187ab684d8c2c Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Thu, 24 Aug 2023 14:01:13 -0700 Subject: [PATCH 2/3] scripts: fix counting checks There were two problems with ${s_count} and ${s_count_str}. 1) ${s_count} and ${s_count_str} are both misnamed: they count the checks, not the scenarios. FIX 1/3: both variables should be prefixed with with "c_", not "s_". 2) There was an off-by-one error with ${c_count} and ${c_count_str}. After running setup_check_variables for the Nth time, ${c_count} is N, while ${c_count_str} is a zero-padded string containing N-1. For example, after the first time setup_check_variables() is run, we have: c_exitfile=tests-output/01-example-00.exit c_count_str=00 c_count=1 FIX 2/3: ${c_count} should be renamed to ${c_count_next}. When 15-readpass-file.sh used ${c_count_new} for the stdout file, we ended up with: output=tests-output/01-example-1.stdout which corresponded to 15-readpass-file-00.exit, which is wrong. FIX 3/3: ${c_count_new} should not be used by anything other than setup_check_variables(); everything else should use ${c_count_str}. This should have included when we added it in: 2023-06-29 scripts: misc fixes ed4c19ad5a55963e69792209a1eafc12f14c068d --- tests/shared_test_functions.sh | 20 +++++++++++--------- tests/shared_valgrind_functions.sh | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/shared_test_functions.sh b/tests/shared_test_functions.sh index ff4fa310..99924060 100644 --- a/tests/shared_test_functions.sh +++ b/tests/shared_test_functions.sh @@ -37,10 +37,12 @@ # and log files. # - s_val_basename: this is the basename for the scenario's # valgrind log files. -# - s_count: this is the count of the scenario's checks (so that -# each check can have distinct files). -# - s_count_str: ${s_count} expressed as a two-digit string. # - s_retval: this is the overall exit code of the scenario. +# - c_count_next: this is the count of the scenario's checks (so that +# each check can have distinct files). +# - c_count_str: the previous value of ${c_count_next}, expressed as a +# two-digit string. In other words, when we're working on the Nth +# check, ${c_count_next} is N, while ${c_count_str} is N-1. # - c_exitfile: this contains the exit code of each check. # - c_valgrind_min: this is the minimum value of USE_VALGRIND # which will enable valgrind checking for this check. @@ -152,7 +154,7 @@ wait_while() { ## setup_check_variables (description, check_prev=1): # Set up the "check" variables ${c_exitfile} and ${c_valgrind_cmd}, the # latter depending on the previously-defined ${c_valgrind_min}. -# Advances the number of checks ${s_count} so that the next call to this +# Advance the number of checks ${c_count_next} so that the next call to this # function will set up new filenames. Write ${description} into a # file. If ${check_prev} is non-zero, check that the previous # ${c_exitfile} exists. @@ -174,18 +176,18 @@ setup_check_variables() { fi # Set up the "exit" file. - s_count_str=$(printf "%02d" "${s_count}") - c_exitfile="${s_basename}-${s_count_str}.exit" + c_count_str=$(printf "%02d" "${c_count_next}") + c_exitfile="${s_basename}-${c_count_str}.exit" # Write the "description" file. printf "%s\n" "${description}" > \ - "${s_basename}-${s_count_str}.desc" + "${s_basename}-${c_count_str}.desc" # Set up the valgrind command (or an empty string). c_valgrind_cmd="$(valgrind_setup_cmd)" # Advances the number of checks. - s_count=$((s_count + 1)) + c_count_next=$((c_count_next + 1)) } ## expected_exitcode (expected, exitcode): @@ -286,7 +288,7 @@ scenario_runner() { # Initialize "scenario" and "check" variables. s_basename=${out}/${basename} s_val_basename=${out_valgrind}/${basename} - s_count=0 + c_count_next=0 c_exitfile="${NO_EXITFILE}" c_valgrind_min=9 c_valgrind_cmd="" diff --git a/tests/shared_valgrind_functions.sh b/tests/shared_valgrind_functions.sh index e4e9033b..0d8e5b99 100644 --- a/tests/shared_valgrind_functions.sh +++ b/tests/shared_valgrind_functions.sh @@ -230,7 +230,7 @@ valgrind_setup_cmd() { return fi - val_logfilename="${s_val_basename}-${s_count_str}-%p.log" + val_logfilename="${s_val_basename}-${c_count_str}-%p.log" c_valgrind_cmd="valgrind \ --log-file=${val_logfilename} \ --track-fds=yes \ From 6d38ae88cf060eda4b21273fc5826ecf1bae335c Mon Sep 17 00:00:00 2001 From: Graham Percival Date: Thu, 24 Aug 2023 14:01:15 -0700 Subject: [PATCH 3/3] Fix indentation of #define ... while (0) This should only have one level of indentation. Check with: git grep -A1 -h "#define" -- "*.h" "*.c" | ggrep -P "^\t\t" There are two instances remaining: getopt.h and readpass.c. Keep those as is. (The "ggrep" is not a typo; this requires gnu grep to find the tabs.) --- libcperciva/alg/sha256_arm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libcperciva/alg/sha256_arm.c b/libcperciva/alg/sha256_arm.c index 84302fe4..e3e5f6b1 100644 --- a/libcperciva/alg/sha256_arm.c +++ b/libcperciva/alg/sha256_arm.c @@ -36,13 +36,13 @@ static const uint32_t Krnd[64] = { /* Round computation. */ #define RND4(S, M, Kp) do { \ - uint32x4_t S0_step; \ - uint32x4_t Wk; \ - S0_step = S[0]; \ - Wk = vaddq_u32(M, vld1q_u32(Kp)); \ - S[0] = vsha256hq_u32(S[0], S[1], Wk); \ - S[1] = vsha256h2q_u32(S[1], S0_step, Wk); \ - } while (0) + uint32x4_t S0_step; \ + uint32x4_t Wk; \ + S0_step = S[0]; \ + Wk = vaddq_u32(M, vld1q_u32(Kp)); \ + S[0] = vsha256hq_u32(S[0], S[1], Wk); \ + S[1] = vsha256h2q_u32(S[1], S0_step, Wk); \ +} while (0) /* Message schedule computation */ #define MSG4(X0, X1, X2, X3) \