public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] Sync timespec-{add,sub} with gnulib
@ 2019-10-31 20:04 Adhemerval Zanella
0 siblings, 0 replies; only message in thread
From: Adhemerval Zanella @ 2019-10-31 20:04 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c1dac8f83ecda0d23f92ddacad52818f658988a4
commit c1dac8f83ecda0d23f92ddacad52818f658988a4
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date: Thu Oct 31 14:46:44 2019 -0300
Sync timespec-{add,sub} with gnulib
It sync with gnulib commit 06011ed74e978613422aca43c0bd92dc44213933.
Reviewed-by: Paul Eggert <eggert@cs.ucla.edu>
Diff:
---
support/timespec-add.c | 20 +++++++-------------
support/timespec-sub.c | 20 +++++++-------------
2 files changed, 14 insertions(+), 26 deletions(-)
diff --git a/support/timespec-add.c b/support/timespec-add.c
index ea9791d..8efb8a6 100644
--- a/support/timespec-add.c
+++ b/support/timespec-add.c
@@ -33,36 +33,30 @@ timespec_add (struct timespec a, struct timespec b)
int ns = a.tv_nsec + b.tv_nsec;
int nsd = ns - TIMESPEC_HZ;
int rns = ns;
- time_t tmin = TYPE_MINIMUM (time_t);
- time_t tmax = TYPE_MAXIMUM (time_t);
if (0 <= nsd)
{
rns = nsd;
- if (bs < tmax)
- bs++;
+ time_t bs1;
+ if (!INT_ADD_WRAPV (bs, 1, &bs1))
+ bs = bs1;
else if (rs < 0)
rs++;
else
goto high_overflow;
}
- /* INT_ADD_WRAPV is not appropriate since time_t might be unsigned.
- In theory time_t might be narrower than int, so plain
- INT_ADD_OVERFLOW does not suffice. */
- if (! INT_ADD_OVERFLOW (rs, bs) && tmin <= rs + bs && rs + bs <= tmax)
- rs += bs;
- else
+ if (INT_ADD_WRAPV (rs, bs, &rs))
{
- if (rs < 0)
+ if (bs < 0)
{
- rs = tmin;
+ rs = TYPE_MINIMUM (time_t);
rns = 0;
}
else
{
high_overflow:
- rs = tmax;
+ rs = TYPE_MAXIMUM (time_t);
rns = TIMESPEC_HZ - 1;
}
}
diff --git a/support/timespec-sub.c b/support/timespec-sub.c
index 0fe6517..cf16ed7 100644
--- a/support/timespec-sub.c
+++ b/support/timespec-sub.c
@@ -33,36 +33,30 @@ timespec_sub (struct timespec a, struct timespec b)
time_t bs = b.tv_sec;
int ns = a.tv_nsec - b.tv_nsec;
int rns = ns;
- time_t tmin = TYPE_MINIMUM (time_t);
- time_t tmax = TYPE_MAXIMUM (time_t);
if (ns < 0)
{
rns = ns + TIMESPEC_HZ;
- if (bs < tmax)
- bs++;
+ time_t bs1;
+ if (!INT_ADD_WRAPV (bs, 1, &bs1))
+ bs = bs1;
else if (- TYPE_SIGNED (time_t) < rs)
rs--;
else
goto low_overflow;
}
- /* INT_SUBTRACT_WRAPV is not appropriate since time_t might be unsigned.
- In theory time_t might be narrower than int, so plain
- INT_SUBTRACT_OVERFLOW does not suffice. */
- if (! INT_SUBTRACT_OVERFLOW (rs, bs) && tmin <= rs - bs && rs - bs <= tmax)
- rs -= bs;
- else
+ if (INT_SUBTRACT_WRAPV (rs, bs, &rs))
{
- if (rs < 0)
+ if (0 < bs)
{
low_overflow:
- rs = tmin;
+ rs = TYPE_MINIMUM (time_t);
rns = 0;
}
else
{
- rs = tmax;
+ rs = TYPE_MAXIMUM (time_t);
rns = TIMESPEC_HZ - 1;
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-10-31 20:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-31 20:04 [glibc] Sync timespec-{add,sub} with gnulib Adhemerval Zanella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).