diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2016-09-16 20:45:32 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2016-09-16 21:03:21 +0300 |
commit | b1365bde2444003ca95bc28ff06bdd34a81839a7 (patch) | |
tree | 7683ad03249aef3c37e9f64f58c3d31ba6ffb08b | |
parent | 457bc16e5514b7cdde175106807b3b4c04256209 (diff) | |
download | libatomic_ops-b1365bde2444003ca95bc28ff06bdd34a81839a7.tar.gz |
Fix SIZET_SAT_ADD for the case of size_t is signed (SunOS 4.X)
Negative size_t value is impossible in a correct C implementation,
but quite possible under SunOS 4.X.
* src/atomic_ops_malloc.c: Include limits.h (unless SIZE_MAX already
defined).
* src/atomic_ops_malloc.c (AO_SIZE_MAX): New macro.
* src/atomic_ops_malloc.c (SIZET_SAT_ADD): Use AO_SIZE_MAX instead of
~(size_t)0.
-rw-r--r-- | src/atomic_ops_malloc.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/atomic_ops_malloc.c b/src/atomic_ops_malloc.c index 7178f49..6d4d81a 100644 --- a/src/atomic_ops_malloc.c +++ b/src/atomic_ops_malloc.c @@ -135,9 +135,19 @@ static char *get_mmaped(size_t sz) return result; } +#ifndef SIZE_MAX +# include <limits.h> +#endif +#ifdef SIZE_MAX +# define AO_SIZE_MAX SIZE_MAX +#else +# define AO_SIZE_MAX (~(size_t)0) +#endif + /* Saturated addition of size_t values. Used to avoid value wrap */ /* around on overflow. The arguments should have no side effects. */ -#define SIZET_SAT_ADD(a, b) ((a) < ~(size_t)(b) ? (a) + (b) : ~(size_t)0) +#define SIZET_SAT_ADD(a, b) \ + ((a) < AO_SIZE_MAX - (b) ? (a) + (b) : AO_SIZE_MAX) /* Allocate an object of size (incl. header) of size > CHUNK_SIZE. */ /* sz includes space for an AO_t-sized header. */ |