Skip to content

Commit 5b85d93

Browse files
committed
switch polyz_unpack unit test to malloc
Signed-off-by: Matthias J. Kannwischer <matthias@kannwischer.eu>
1 parent 881027e commit 5b85d93

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

test/test_unit.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stddef.h>
77
#include <stdio.h>
8+
#include <stdlib.h>
89
#include <string.h>
910
#include "notrandombytes/notrandombytes.h"
1011

@@ -103,20 +104,35 @@ static int test_mld_polyz_unpack_core(const uint8_t *input,
103104

104105
static int test_native_polyz_unpack(void)
105106
{
106-
uint8_t test_bytes[MLDSA_POLYZ_PACKEDBYTES];
107+
uint8_t *test_bytes = malloc(MLDSA_POLYZ_PACKEDBYTES);
107108
int i;
109+
int rc = 0;
108110

109-
memset(test_bytes, 0, MLDSA_POLYZ_PACKEDBYTES);
110-
CHECK(test_mld_polyz_unpack_core(test_bytes, "polyz_unpack_zeros") == 0);
111+
if (test_bytes == NULL)
112+
{
113+
return 1;
114+
}
111115

116+
memset(test_bytes, 0, MLDSA_POLYZ_PACKEDBYTES);
117+
if (test_mld_polyz_unpack_core(test_bytes, "polyz_unpack_zeros") != 0)
118+
{
119+
rc = 1;
120+
goto cleanup;
121+
}
112122

113123
for (i = 0; i < NUM_RANDOM_TESTS; i++)
114124
{
115125
randombytes(test_bytes, MLDSA_POLYZ_PACKEDBYTES);
116-
CHECK(test_mld_polyz_unpack_core(test_bytes, "polyz_unpack_random") == 0);
126+
if (test_mld_polyz_unpack_core(test_bytes, "polyz_unpack_random") != 0)
127+
{
128+
rc = 1;
129+
goto cleanup;
130+
}
117131
}
118132

119-
return 0;
133+
cleanup:
134+
free(test_bytes);
135+
return rc;
120136
}
121137
#endif /* MLD_USE_NATIVE_POLYZ_UNPACK_17 || MLD_USE_NATIVE_POLYZ_UNPACK_19 */
122138

0 commit comments

Comments
 (0)