xtest: Explicitly initialize local variables
This change initializes all local variables to prevent build issues
(warnings and/or errors) in OP-TEE test package. This change uses
= { } for non-scalar variables and = 0 for scalar variables when there
is no obvious value. This change falls back to memset() only when
neither = { } nor = 0 is applicable, here pthread_t typed variable
and variable size arrays.
Signed-off-by: Etienne Carriere <etienne.carriere@linaro.org>
Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c
index df152d4..73cc4ad 100644
--- a/host/xtest/regression_1000.c
+++ b/host/xtest/regression_1000.c
@@ -51,8 +51,8 @@
static void xtest_crypto_test(struct xtest_crypto_session *cs)
{
- uint32_t ret_orig;
- uint8_t crypt_out[16];
+ uint32_t ret_orig = 0;
+ uint8_t crypt_out[16] = { };
uint8_t crypt_in[16] = { 22, 17 };
crypt_in[15] = 60;
@@ -81,7 +81,7 @@
Do_ADBG_BeginSubCase(cs->c, "AES decrypt");
{
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint8_t out[16];
+ uint8_t out[16] = { };
op.params[0].tmpref.buffer = crypt_out;
op.params[0].tmpref.size = sizeof(crypt_out);
@@ -118,7 +118,7 @@
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
};
- uint8_t out[32] = { 0 };
+ uint8_t out[32] = { };
op.params[0].tmpref.buffer = (void *)sha256_in;
op.params[0].tmpref.size = sizeof(sha256_in);
@@ -160,7 +160,7 @@
0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
};
- uint8_t out[sizeof(exp_out)];
+ uint8_t out[sizeof(exp_out)] = { };
op.params[0].tmpref.buffer = (void *)in;
op.params[0].tmpref.size = sizeof(in);
@@ -202,7 +202,7 @@
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
};
- uint8_t out[sizeof(exp_out)];
+ uint8_t out[sizeof(exp_out)] = { };
op.params[0].tmpref.buffer = (void *)in;
op.params[0].tmpref.size = sizeof(in);
@@ -232,9 +232,9 @@
static void xtest_tee_test_1001(ADBG_Case_t *c)
{
- TEEC_Result res;
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Result res = TEEC_ERROR_GENERIC;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
/* Pseudo TA is optional: warn and nicely exit if not found */
res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
@@ -253,13 +253,13 @@
static void xtest_tee_test_1002(ADBG_Case_t *c)
{
- TEEC_Result res;
- TEEC_Session session = { 0 };
+ TEEC_Result res = TEEC_ERROR_GENERIC;
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint32_t ret_orig;
- uint8_t buf[16 * 1024];
+ uint32_t ret_orig = 0;
+ uint8_t buf[16 * 1024] = { };
uint8_t exp_sum = 0;
- size_t n;
+ size_t n = 0;
/* Pseudo TA is optional: warn and nicely exit if not found */
res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
@@ -304,9 +304,9 @@
static void *test_1003_thread(void *arg)
{
struct test_1003_arg *a = arg;
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
size_t rounds = 64 * 1024;
- size_t n;
+ size_t n = 0;
a->res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid,
NULL, &a->error_orig);
@@ -349,25 +349,26 @@
return NULL;
}
+#define TEST_1003_THREAD_COUNT (3 * 2)
+
static void xtest_tee_test_1003(ADBG_Case_t *c)
{
- size_t num_threads = 3 * 2;
- TEEC_Result res;
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Result res = TEEC_ERROR_GENERIC;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
size_t repeat = 20;
- pthread_t thr[num_threads];
- struct test_1003_arg arg[num_threads];
+ struct test_1003_arg arg[TEST_1003_THREAD_COUNT] = { };
size_t max_read_concurrency = 0;
size_t max_read_waiters = 0;
size_t num_concurrent_read_lockers = 0;
size_t num_concurrent_read_waiters = 0;
- size_t n;
- size_t nt = num_threads;
- double mean_read_concurrency;
- double mean_read_waiters;
+ size_t n = 0;
+ size_t nt = TEST_1003_THREAD_COUNT;
+ double mean_read_concurrency = 0;
+ double mean_read_waiters = 0;
size_t num_writers = 0;
size_t num_readers = 0;
+ pthread_t thr[TEST_1003_THREAD_COUNT] = { };
/* Pseudo TA is optional: warn and nicely exit if not found */
res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
@@ -379,8 +380,6 @@
ADBG_EXPECT_TEEC_SUCCESS(c, res);
TEEC_CloseSession(&session);
- memset(arg, 0, sizeof(arg));
-
for (n = 0; n < nt; n++) {
if (n % 3) {
arg[n].test_type = PTA_MUTEX_TEST_READER;
@@ -418,8 +417,8 @@
mean_read_waiters = (double)num_concurrent_read_waiters /
(double)(repeat * num_readers);
- Do_ADBG_Log(" Number of parallel threads: %zu (%zu writers and %zu readers)",
- num_threads, num_writers, num_readers);
+ Do_ADBG_Log(" Number of parallel threads: %d (%zu writers and %zu readers)",
+ TEST_1003_THREAD_COUNT, num_writers, num_readers);
Do_ADBG_Log(" Max read concurrency: %zu", max_read_concurrency);
Do_ADBG_Log(" Max read waiters: %zu", max_read_waiters);
Do_ADBG_Log(" Mean read concurrency: %g", mean_read_concurrency);
@@ -430,8 +429,8 @@
static void xtest_tee_test_1004(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
struct xtest_crypto_session cs = { c, &session, TA_CRYPT_CMD_SHA256,
TA_CRYPT_CMD_AES256ECB_ENC,
TA_CRYPT_CMD_AES256ECB_DEC };
@@ -450,9 +449,9 @@
static void xtest_tee_test_invalid_mem_access(ADBG_Case_t *c, unsigned int n)
{
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint32_t ret_orig;
+ uint32_t ret_orig = 0;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
@@ -481,12 +480,11 @@
static void xtest_tee_test_invalid_mem_access2(ADBG_Case_t *c, unsigned int n,
size_t size)
{
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint32_t ret_orig;
- TEEC_SharedMemory shm;
+ uint32_t ret_orig = 0;
+ TEEC_SharedMemory shm = { };
- memset(&shm, 0, sizeof(shm));
shm.size = size;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -521,10 +519,10 @@
static void xtest_tee_test_1005(ADBG_Case_t *c)
{
- uint32_t ret_orig;
+ uint32_t ret_orig = 0;
#define MAX_SESSIONS 3
TEEC_Session sessions[MAX_SESSIONS];
- int i;
+ int i = 0;
for (i = 0; i < MAX_SESSIONS; i++) {
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -541,10 +539,10 @@
static void xtest_tee_test_1006(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint8_t buf[32];
+ uint8_t buf[32] = { };
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
@@ -567,8 +565,8 @@
static void xtest_tee_test_1007(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
@@ -604,7 +602,7 @@
static FILE *open_ta_file(const TEEC_UUID *uuid, const char *mode)
{
- char buf[PATH_MAX];
+ char buf[PATH_MAX] = { };
snprintf(buf, sizeof(buf),
"%s/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.ta",
@@ -619,16 +617,16 @@
static bool load_corrupt_ta(ADBG_Case_t *c, size_t offs, uint8_t mask)
{
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
TEEC_UUID uuid = PTA_SECSTOR_TA_MGMT_UUID;
- TEEC_Result res;
- uint32_t ret_orig;
+ TEEC_Result res = TEEC_ERROR_GENERIC;
+ uint32_t ret_orig = 0;
FILE *f = NULL;
bool r = false;
uint8_t *buf = NULL;
- size_t sz;
- size_t fread_res;
+ size_t sz = 0;
+ size_t fread_res = 0;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &uuid, NULL, &ret_orig)))
@@ -674,9 +672,9 @@
static void xtest_tee_test_1008(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
- TEEC_Session session_crypt = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ TEEC_Session session_crypt = { };
+ uint32_t ret_orig = 0;
Do_ADBG_BeginSubCase(c, "Invoke command");
{
@@ -718,7 +716,7 @@
Do_ADBG_BeginSubCase(c, "Create session fail");
{
- size_t n;
+ size_t n = 0;
(void)ADBG_EXPECT_TEEC_RESULT(c, TEEC_ERROR_GENERIC,
xtest_teec_open_session(&session_crypt,
@@ -777,10 +775,12 @@
static void xtest_tee_test_1009_subcase(ADBG_Case_t *c, const char *subcase,
uint32_t timeout, bool cancel)
{
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
pthread_t thr;
+ memset(&thr, 0, sizeof(thr));
+
Do_ADBG_BeginSubCase(c, "%s", subcase);
{
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
@@ -835,8 +835,8 @@
static void xtest_tee_test_1010(ADBG_Case_t *c)
{
- unsigned int n;
- unsigned int idx;
+ unsigned int n = 0;
+ unsigned int idx = 0;
size_t memref_sz[] = { 1024, 65536 };
for (n = 1; n <= 5; n++) {
@@ -862,8 +862,8 @@
static void xtest_tee_test_1011(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
struct xtest_crypto_session cs = {
c, &session, TA_RPC_CMD_CRYPT_SHA256,
TA_RPC_CMD_CRYPT_AES256ECB_ENC,
@@ -911,9 +911,9 @@
*/
static void xtest_tee_test_1012(ADBG_Case_t *c)
{
- TEEC_Session session1 = { 0 };
- TEEC_Session session2 = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session1 = { };
+ TEEC_Session session2 = { };
+ uint32_t ret_orig = 0;
TEEC_UUID uuid = sims_test_ta_uuid;
Do_ADBG_BeginSubCase(c, "Single Instance Multi Session");
@@ -925,8 +925,8 @@
0xE9, 0xC3, 0xEF, 0x8A, 0xB2, 0x34, 0x53, 0xE6,
0xF0, 0x74, 0x9C, 0xD6, 0x36, 0xE7, 0xA8, 0x8E
};
- uint8_t out[32] = { 0 };
- int i;
+ uint8_t out[32] = { };
+ int i = 0;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session1, &uuid, NULL,
@@ -1031,7 +1031,7 @@
static void *test_1013_thread(void *arg)
{
struct test_1013_thread_arg *a = arg;
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
uint8_t p2 = TEEC_NONE;
uint8_t p3 = TEEC_NONE;
@@ -1071,14 +1071,12 @@
static void xtest_tee_test_1013_single(ADBG_Case_t *c, double *mean_concurrency,
const TEEC_UUID *uuid)
{
- size_t num_threads = NUM_THREADS;
- size_t nt;
- size_t n;
+ size_t nt = 0;
+ size_t n = 0;
size_t repeat = 1000;
- pthread_t thr[num_threads];
- TEEC_SharedMemory shm;
- size_t max_concurrency;
- struct test_1013_thread_arg arg[num_threads];
+ TEEC_SharedMemory shm = { };
+ size_t max_concurrency = 0;
+ struct test_1013_thread_arg arg[NUM_THREADS] = { };
static const uint8_t sha256_in[] = { 'a', 'b', 'c' };
static const uint8_t sha256_out[] = {
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
@@ -1086,12 +1084,12 @@
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
};
- uint8_t out[32] = { 0 };
+ uint8_t out[32] = { };
+ pthread_t thr[NUM_THREADS] = { };
Do_ADBG_BeginSubCase(c, "Busy loop repeat %zu", repeat * 10);
*mean_concurrency = 0;
- memset(&shm, 0, sizeof(shm));
shm.size = sizeof(struct ta_concurrent_shm);
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -1099,9 +1097,8 @@
return;
memset(shm.buffer, 0, shm.size);
- memset(arg, 0, sizeof(arg));
max_concurrency = 0;
- nt = num_threads;
+ nt = NUM_THREADS;
for (n = 0; n < nt; n++) {
arg[n].uuid = uuid;
@@ -1127,7 +1124,7 @@
* best result there).
*/
(void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, >, 0);
- (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, num_threads);
+ (void)ADBG_EXPECT_COMPARE_UNSIGNED(c, max_concurrency, <=, NUM_THREADS);
*mean_concurrency += max_concurrency;
Do_ADBG_EndSubCase(c, "Busy loop repeat %zu", repeat * 10);
@@ -1135,7 +1132,7 @@
memset(shm.buffer, 0, shm.size);
memset(arg, 0, sizeof(arg));
max_concurrency = 0;
- nt = num_threads;
+ nt = NUM_THREADS;
for (n = 0; n < nt; n++) {
arg[n].uuid = uuid;
@@ -1168,9 +1165,9 @@
static void xtest_tee_test_1013(ADBG_Case_t *c)
{
- int i;
- double mean_concurrency;
- double concurrency;
+ int i = 0;
+ double mean_concurrency = 0;
+ double concurrency = 0;
int nb_loops = 24;
if (level == 0)
@@ -1216,8 +1213,8 @@
int loop = 10;
int ion_heap = DEFAULT_ION_HEAP_TYPE;
int rnd_offset = 1;
- int test;
- int ret;
+ int test = 0;
+ int ret = 0;
test = TEST_NS_TO_TA;
Do_ADBG_BeginSubCase(c, "SDP: NonSecure client invokes a SDP TA");
@@ -1249,9 +1246,9 @@
static void xtest_tee_test_1015(ADBG_Case_t *c)
{
- TEEC_Result res;
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Result res = TEEC_ERROR_GENERIC;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
/* Pseudo TA is optional: warn and nicely exit if not found */
res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,
@@ -1272,9 +1269,9 @@
static void xtest_tee_test_1016(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint32_t ret_orig;
+ uint32_t ret_orig = 0;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
@@ -1295,13 +1292,12 @@
static void xtest_tee_test_1017(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint32_t ret_orig;
- TEEC_SharedMemory shm;
+ uint32_t ret_orig = 0;
+ TEEC_SharedMemory shm = { };
size_t page_size = 4096;
- memset(&shm, 0, sizeof(shm));
shm.size = 8 * page_size;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -1352,13 +1348,12 @@
static void xtest_tee_test_1018(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
+ TEEC_Session session = { };
TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
- uint32_t ret_orig;
- TEEC_SharedMemory shm;
+ uint32_t ret_orig = 0;
+ TEEC_SharedMemory shm = { };
size_t page_size = 4096;
- memset(&shm, 0, sizeof(shm));
shm.size = 8 * page_size;
shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
@@ -1415,8 +1410,8 @@
#if defined(CFG_TA_DYNLINK)
static void xtest_tee_test_1019(ADBG_Case_t *c)
{
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
if (!ADBG_EXPECT_TEEC_SUCCESS(c,
xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
@@ -1442,9 +1437,9 @@
static void xtest_tee_test_1020(ADBG_Case_t *c)
{
- TEEC_Result res;
- TEEC_Session session = { 0 };
- uint32_t ret_orig;
+ TEEC_Result res = TEEC_ERROR_GENERIC;
+ TEEC_Session session = { };
+ uint32_t ret_orig = 0;
/* Pseudo TA is optional: warn and nicely exit if not found */
res = xtest_teec_open_session(&session, &pta_invoke_tests_ta_uuid, NULL,