Skip to content

Commit

Permalink
cast to fn pointer type
Browse files Browse the repository at this point in the history
  • Loading branch information
toidiu committed Nov 16, 2024
1 parent 1763e6b commit 04a8319
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tests/unit/s2n_random_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,8 @@ static int s2n_random_rand_bytes_after_cleanup_cb(struct random_test_case *test_
return S2N_SUCCESS;
}

typedef int (*s2n_rand_meth_fn_type)(unsigned char *buf, int num);

static int s2n_random_rand_bytes_before_init(struct random_test_case *test_case)
{
if (s2n_supports_custom_rand()) {
Expand All @@ -800,15 +802,14 @@ static int s2n_random_rand_bytes_before_init(struct random_test_case *test_case)
EXPECT_EQUAL(RAND_bytes(rndbytes, sizeof(rndbytes)), 1);
const RAND_METHOD *rand_method = RAND_get_rand_method();
EXPECT_NOT_NULL(rand_method);
EXPECT_NOT_EQUAL((void *) rand_method->bytes, (void *) s2n_openssl_compat_rand);
EXPECT_NOT_EQUAL((s2n_rand_meth_fn_type) rand_method->bytes, (s2n_rand_meth_fn_type) s2n_openssl_compat_rand);

/* int (*bytes)(uint8_t *buf, size_t num); */
EXPECT_SUCCESS(s2n_init());

/* The global random method is overridden after calling s2n_init() */
const RAND_METHOD *custom_rand_method = RAND_get_rand_method();
EXPECT_NOT_NULL(custom_rand_method);
EXPECT_EQUAL((void *) custom_rand_method->bytes, (void *) s2n_openssl_compat_rand);
EXPECT_EQUAL((s2n_rand_meth_fn_type) custom_rand_method->bytes, (s2n_rand_meth_fn_type) s2n_openssl_compat_rand);

/* RAND_bytes is still successful */
EXPECT_EQUAL(RAND_bytes(rndbytes, sizeof(rndbytes)), 1);
Expand Down

0 comments on commit 04a8319

Please sign in to comment.