Remove invalid left shifts of -1.
Bug: 24492248 Shifting sign bits left is considered undefined behavior, so we need to switch these uses to unsigned equivalents. The time_t-related code is updated relative to upstream sources. Change-Id: I226e5a929a10f5c57dfcb90c748fdac34eb377c2
This commit is contained in:
parent
8b279eadd3
commit
23360cc498
2 changed files with 15 additions and 10 deletions
|
@ -80,7 +80,7 @@ static inline int SEMCOUNT_TO_VALUE(unsigned int sval) {
|
|||
#define SEMCOUNT_ONE SEMCOUNT_FROM_VALUE(1)
|
||||
|
||||
// The value -1 as a sem->count bit-pattern.
|
||||
#define SEMCOUNT_MINUS_ONE SEMCOUNT_FROM_VALUE(-1)
|
||||
#define SEMCOUNT_MINUS_ONE SEMCOUNT_FROM_VALUE(~0U)
|
||||
|
||||
#define SEMCOUNT_DECREMENT(sval) (((sval) - (1U << SEMCOUNT_VALUE_SHIFT)) & SEMCOUNT_VALUE_MASK)
|
||||
#define SEMCOUNT_INCREMENT(sval) (((sval) + (1U << SEMCOUNT_VALUE_SHIFT)) & SEMCOUNT_VALUE_MASK)
|
||||
|
|
|
@ -328,15 +328,20 @@ const char * scheck(const char * string, const char * format);
|
|||
#define TYPE_SIGNED(type) (((type) -1) < 0)
|
||||
#endif /* !defined TYPE_SIGNED */
|
||||
|
||||
/* The minimum and maximum finite time values. */
|
||||
static time_t const time_t_min =
|
||||
(TYPE_SIGNED(time_t)
|
||||
? (time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1)
|
||||
: 0);
|
||||
static time_t const time_t_max =
|
||||
(TYPE_SIGNED(time_t)
|
||||
? - (~ 0 < 0) - ((time_t) -1 << (CHAR_BIT * sizeof (time_t) - 1))
|
||||
: -1);
|
||||
#define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0)
|
||||
|
||||
/* Max and min values of the integer type T, of which only the bottom
|
||||
* B bits are used, and where the highest-order used bit is considered
|
||||
* to be a sign bit if T is signed. */
|
||||
#define MAXVAL(t, b) \
|
||||
((t) (((t) 1 << ((b) - 1 - TYPE_SIGNED(t))) \
|
||||
- 1 + ((t) 1 << ((b) - 1 - TYPE_SIGNED(t)))))
|
||||
#define MINVAL(t, b) \
|
||||
((t) (TYPE_SIGNED(t) ? - TWOS_COMPLEMENT(t) - MAXVAL(t, b) : 0))
|
||||
|
||||
/* The minimum and maximum finite time values. This assumes no padding. */
|
||||
static time_t const time_t_min = MINVAL(time_t, TYPE_BIT(time_t));
|
||||
static time_t const time_t_max = MAXVAL(time_t, TYPE_BIT(time_t));
|
||||
|
||||
#ifndef INT_STRLEN_MAXIMUM
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue