From 1f20503e46b237fdb78d162d3b24d56472b1291b Mon Sep 17 00:00:00 2001 From: Chris Friedt Date: Wed, 16 Nov 2022 22:08:17 -0500 Subject: [PATCH] tests: posix: common: avoid direct pthread_attr_t field access Avoid directly accessing fields in `pthread_attr_t` and only access / mutate them with POSIX functions. Signed-off-by: Chris Friedt --- tests/posix/common/src/pthread.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index d9a2d569b7d..92e80c2b055 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -319,9 +319,10 @@ ZTEST(posix_apis, test_posix_pthread_execution) /* TESTPOINTS: Retrieve set stack attributes and compare */ pthread_attr_setstack(&attr[i], &stack_e[i][0], STACKS); + stackaddr = NULL; pthread_attr_getstack(&attr[i], &stackaddr, &stacksize); - zassert_equal_ptr(attr[i].stack, stackaddr, - "stack attribute addresses do not match!"); + zassert_equal_ptr(&stack_e[i][0], stackaddr, + "stack attribute addresses do not match!"); zassert_equal(STACKS, stacksize, "stack sizes do not match!"); pthread_attr_getstacksize(&attr[i], &stacksize); @@ -446,7 +447,7 @@ ZTEST(posix_apis, test_posix_pthread_error_condition) zassert_equal(pthread_setschedparam(PTHREAD_INVALID, policy, ¶m), ESRCH, "set schedparam with NULL error"); - attr.initialized = 0U; + attr = (pthread_attr_t){0}; zassert_equal(pthread_attr_getdetachstate(&attr, &detach), EINVAL, "get detach state error"); @@ -571,7 +572,7 @@ ZTEST(posix_apis, test_posix_pthread_create_negative) ret = pthread_attr_init(&attr1); zassert_false(ret, "attr1 initialized failed"); - attr1.stack = NULL; + attr1 = (pthread_attr_t){0}; ret = pthread_create(&pthread1, &attr1, create_thread1, (void *)1); zassert_equal(ret, EINVAL, "create successful with NULL attr");