Skip to content

Commit 3458527

Browse files
Christopher Friedtfabiobaltieri
authored andcommitted
posix: pthread_getspecific: fix for coverity issue cid 334909
* remove unneeded line of code that duplicated the first part of the SYS_SLIST_FOR_EACH_NODE() expansion. * return NULL if pthread_self() is not a valid pthread Signed-off-by: Christopher Friedt <[email protected]>
1 parent c48d61a commit 3458527

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/posix/key.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,17 @@ int pthread_setspecific(pthread_key_t key, const void *value)
248248
void *pthread_getspecific(pthread_key_t key)
249249
{
250250
pthread_key_obj *key_obj;
251-
struct posix_thread *thread = to_posix_thread(pthread_self());
251+
struct posix_thread *thread;
252252
pthread_thread_data *thread_spec_data;
253253
void *value = NULL;
254254
sys_snode_t *node_l;
255255
k_spinlock_key_t key_key;
256256

257+
thread = to_posix_thread(pthread_self());
258+
if (thread == NULL) {
259+
return NULL;
260+
}
261+
257262
key_key = k_spin_lock(&pthread_key_lock);
258263

259264
key_obj = get_posix_key(key);
@@ -262,8 +267,6 @@ void *pthread_getspecific(pthread_key_t key)
262267
return NULL;
263268
}
264269

265-
node_l = sys_slist_peek_head(&(thread->key_list));
266-
267270
/* Traverse the list of keys set by the thread, looking for key */
268271

269272
SYS_SLIST_FOR_EACH_NODE(&(thread->key_list), node_l) {

0 commit comments

Comments
 (0)