summaryrefslogtreecommitdiff
path: root/ptw32_semwait.c
diff options
context:
space:
mode:
Diffstat (limited to 'ptw32_semwait.c')
-rw-r--r--ptw32_semwait.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/ptw32_semwait.c b/ptw32_semwait.c
index 8b23d11..111cb80 100644
--- a/ptw32_semwait.c
+++ b/ptw32_semwait.c
@@ -77,8 +77,18 @@ ptw32_semwait (sem_t * sem)
{
if ((result = pthread_mutex_lock (&s->lock)) == 0)
{
- int v = --s->value;
+ int v;
+ /* See sem_destroy.c
+ */
+ if (*sem == NULL)
+ {
+ (void) pthread_mutex_unlock (&s->lock);
+ errno = EINVAL;
+ return -1;
+ }
+
+ v = --s->value;
(void) pthread_mutex_unlock (&s->lock);
if (v < 0)
@@ -89,6 +99,13 @@ ptw32_semwait (sem_t * sem)
#ifdef NEED_SEM
if (pthread_mutex_lock (&s->lock) == 0)
{
+ if (*sem == NULL)
+ {
+ (void) pthread_mutex_unlock (&s->lock);
+ errno = EINVAL;
+ return -1;
+ }
+
if (s->leftToUnblock > 0)
{
--s->leftToUnblock;