From 56e25a91e9e25eba8da099efa89c3c487c3490cf Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sun, 6 Nov 2011 12:39:04 +0100 Subject: pthread_getspecific, pthread_setspecific: check the key validity When getting a TSD, handle gracefully the case of an invalid key. When setting a TSD, check for the validity of the key as recommended (although not required) by POSIX. This also avoids potentially filling the `thread_specifics' hash of threads with TSD of invalid keys. Add two simple checks in test-7.c for the two situations above. * sysdeps/hurd/pt-getspecific.c (pthread_getspecific): Check the validity of the specified key. * sysdeps/hurd/pt-setspecific.c (pthread_setspecific): Likewise. * tests/test-7.c (main): Add two assertions. --- tests/test-7.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/test-7.c') diff --git a/tests/test-7.c b/tests/test-7.c index 8159be3..22fb1ca 100644 --- a/tests/test-7.c +++ b/tests/test-7.c @@ -42,6 +42,9 @@ main (int argc, char **argv) assert ((pthread_t) val == pthread_self ()); } + assert (pthread_getspecific ((pthread_key_t) 0) == NULL); + assert (pthread_setspecific ((pthread_key_t) 0, (void *) 0x1) == EINVAL); + for (i = 0; i < KEYS; i ++) err = pthread_key_create (&key[i], des); -- cgit v1.2.3