Cygwin: clock.h: add valid_timespec() to check timespec for validity
Use throughout, drop local timespec_bad() in timer.cc. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
parent
7f983079d4
commit
397526dee8
|
@ -766,7 +766,7 @@ aiosuspend (const struct aiocb *const aiolist[],
|
|||
if (timeout)
|
||||
{
|
||||
to = *timeout;
|
||||
if (to.tv_sec < 0 || to.tv_nsec < 0 || to.tv_nsec > NSPERSEC)
|
||||
if (!valid_timespec (to))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
|
|
|
@ -166,4 +166,12 @@ ts_diff (const struct timespec &ts0, struct timespec &ts1)
|
|||
ts1.tv_sec -= ts0.tv_sec;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
valid_timespec (const timespec& ts)
|
||||
{
|
||||
if (ts.tv_nsec < 0 || ts.tv_nsec >= NSPERSEC || ts.tv_sec < 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /*__CLOCK_H__*/
|
||||
|
|
|
@ -181,9 +181,7 @@ ipc_cond_timedwait (HANDLE evt, HANDLE mtx, const struct timespec *abstime)
|
|||
++cnt;
|
||||
if (abstime)
|
||||
{
|
||||
if (abstime->tv_sec < 0
|
||||
|| abstime->tv_nsec < 0
|
||||
|| abstime->tv_nsec >= NSPERSEC)
|
||||
if (!valid_timespec (*abstime))
|
||||
return EINVAL;
|
||||
|
||||
/* If a timeout is set, we create a waitable timer to wait for.
|
||||
|
|
|
@ -69,7 +69,7 @@ clock_nanosleep (clockid_t clk_id, int flags, const struct timespec *rqtp,
|
|||
|
||||
__try
|
||||
{
|
||||
if (rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 || rqtp->tv_nsec >= NSPERSEC)
|
||||
if (!valid_timespec (*rqtp))
|
||||
return EINVAL;
|
||||
}
|
||||
__except (NO_ERROR)
|
||||
|
@ -654,8 +654,7 @@ sigtimedwait (const sigset_t *set, siginfo_t *info, const timespec *timeout)
|
|||
|
||||
if (timeout)
|
||||
{
|
||||
if (timeout->tv_sec < 0
|
||||
|| timeout->tv_nsec < 0 || timeout->tv_nsec > NSPERSEC)
|
||||
if (!valid_timespec (*timeout))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return -1;
|
||||
|
|
|
@ -2549,9 +2549,7 @@ pthread_convert_abstime (clockid_t clock_id, const struct timespec *abstime,
|
|||
struct timespec tp;
|
||||
|
||||
/* According to SUSv3, the abstime value must be checked for validity. */
|
||||
if (abstime->tv_sec < 0
|
||||
|| abstime->tv_nsec < 0
|
||||
|| abstime->tv_nsec >= NSPERSEC)
|
||||
if (!valid_timespec (*abstime))
|
||||
return EINVAL;
|
||||
|
||||
/* Check for immediate timeout before converting */
|
||||
|
|
|
@ -342,17 +342,6 @@ timer_thread (VOID *x)
|
|||
return tt->thread_func ();
|
||||
}
|
||||
|
||||
static inline bool
|
||||
timespec_bad (const timespec& t)
|
||||
{
|
||||
if (t.tv_nsec < 0 || t.tv_nsec >= NSPERSEC || t.tv_sec < 0)
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
timer_tracker::settime (int in_flags, const itimerspec *value, itimerspec *ovalue)
|
||||
{
|
||||
|
@ -366,8 +355,12 @@ timer_tracker::settime (int in_flags, const itimerspec *value, itimerspec *ovalu
|
|||
__leave;
|
||||
}
|
||||
|
||||
if (timespec_bad (value->it_value) || timespec_bad (value->it_interval))
|
||||
__leave;
|
||||
if (!valid_timespec (value->it_value)
|
||||
|| !valid_timespec (value->it_interval))
|
||||
{
|
||||
set_errno (EINVAL);
|
||||
__leave;
|
||||
}
|
||||
|
||||
lock_timer_tracker here;
|
||||
cancel ();
|
||||
|
|
Loading…
Reference in New Issue