Skip to content

Commit 3a47bfb

Browse files
committed
tests: fix check-source-text and clang-tidy findings in Part-3 tests
check-source-text (rule I) flags error-code identifiers used as comparison operands even inside comments. Reword three comments so the code name is no longer written as "(ret == PUBLIC_KEY_E)" / "(ret != CRYPTOCB_UNAVAILABLE)" (test_kdf.c, test_ed448.c); the bare token on its own is fine. clang-tidy reported a possible 0-byte malloc in test_mlkem.c: the ML-KEM key/ciphertext sizes come from wc_MlKemKey_*Size() queries, which the analyzer cannot prove nonzero. Guard each XMALLOC with a >0 check so the allocation size is provably positive; the ExpectNotNull() checks still catch a 0-size query at runtime.
1 parent 004cc22 commit 3a47bfb

3 files changed

Lines changed: 12 additions & 6 deletions

File tree

tests/api/test_ed448.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ int test_wc_ed448_check_key_decisions(void)
13531353

13541354
/* Same construction but with an extra byte (p[1]) perturbed so the
13551355
* second range-check loop exits early with ret == 0 before the final
1356-
* byte compare runs -- closes that compare's (ret == PUBLIC_KEY_E)
1356+
* byte compare runs -- closes that compare's PUBLIC_KEY_E
13571357
* guard operand's FALSE side. */
13581358
near_p[1] = 0x00;
13591359
ExpectIntEQ(wc_ed448_init(&freshKey), 0);

tests/api/test_kdf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#define TEST_KDF_CRYPTOCB_DEVID 0x4b444630 /* "KDF0" */
6060

6161
/* Toggled by the test below: when set, the callback fails outright instead
62-
* of computing the KDF, giving the (ret != CRYPTOCB_UNAVAILABLE) guard in
62+
* of computing the KDF, giving the CRYPTOCB_UNAVAILABLE fall-through guard in
6363
* wc_KDA_KDF_twostep_cmac an independence pair (dispatch-taken-and-fails vs
6464
* dispatch-taken-and-succeeds), both within this one registered devId. */
6565
static int test_kdf_cryptocb_force_fail = 0;
@@ -631,7 +631,7 @@ int test_wc_KdfDecisionCoverage(void)
631631

632632
#if defined(WOLF_CRYPTO_CB)
633633
/* devId != INVALID_DEVID: dispatch taken. Independence pair for
634-
* the (ret != CRYPTOCB_UNAVAILABLE) guard: succeeds, then fails
634+
* the CRYPTOCB_UNAVAILABLE fall-through guard: succeeds, then fails
635635
* outright, both via the SAME registered devId. */
636636
ExpectIntEQ(wc_CryptoCb_RegisterDevice(TEST_KDF_CRYPTOCB_DEVID,
637637
test_kdf_cryptocb, NULL), 0);

tests/api/test_mlkem.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4148,9 +4148,15 @@ static int mlkem_feature_roundtrip(int type)
41484148

41494149
ExpectIntEQ(wc_MlKemKey_MakeKey(key, &rng), 0);
41504150

4151-
priv = (byte*)XMALLOC(privLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4152-
pub = (byte*)XMALLOC(pubLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4153-
ct = (byte*)XMALLOC(ctLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4151+
/* The size queries above set these; guard each allocation so static
4152+
* analysis sees a nonzero size (clang-tidy flags a possible 0-byte
4153+
* malloc otherwise). ExpectNotNull below still catches a 0-size query. */
4154+
if (privLen > 0)
4155+
priv = (byte*)XMALLOC(privLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4156+
if (pubLen > 0)
4157+
pub = (byte*)XMALLOC(pubLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
4158+
if (ctLen > 0)
4159+
ct = (byte*)XMALLOC(ctLen, NULL, DYNAMIC_TYPE_TMP_BUFFER);
41544160
ExpectNotNull(priv);
41554161
ExpectNotNull(pub);
41564162
ExpectNotNull(ct);

0 commit comments

Comments
 (0)