aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-09-01 15:14:18 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-09-01 15:14:18 -0400
commit3a0f8e7d3f9a54ab34b69d1fc8c9f7806d67521a (patch)
treed4970c6f0f6ba96bc033a187b9d9944248fa4bfc /src
parente50d401a83968436c5d794a77b2cc8fa0a31906d (diff)
downloadpostgresql-3a0f8e7d3f9a54ab34b69d1fc8c9f7806d67521a.tar.gz
postgresql-3a0f8e7d3f9a54ab34b69d1fc8c9f7806d67521a.zip
Make [U]INT64CONST safe for use in #if conditions.
Instead of using a cast to force the constant to be the right width, assume we can plaster on an L, UL, LL, or ULL suffix as appropriate. The old approach to this is very hoary, dating from before we were willing to require compilers to have working int64 types. This fix makes the PG_INT64_MIN, PG_INT64_MAX, and PG_UINT64_MAX constants safe to use in preprocessor conditions, where a cast doesn't work. Other symbolic constants that might be defined using [U]INT64CONST are likewise safer than before. Also fix the SIZE_MAX macro to be similarly safe, if we are forced to provide a definition for that. The test added in commit 2e70d6b5e happens to do what we want even with the hack "(size_t) -1" definition, but we could easily get burnt on other tests in future. Back-patch to all supported branches, like the previous commits. Discussion: https://postgr.es/m/15883.1504278595@sss.pgh.pa.us
Diffstat (limited to 'src')
-rw-r--r--src/include/c.h21
-rw-r--r--src/include/pg_config.h.in4
-rw-r--r--src/include/pg_config.h.win328
3 files changed, 11 insertions, 22 deletions
diff --git a/src/include/c.h b/src/include/c.h
index f1f8b11877a..179e6248c7e 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -285,6 +285,8 @@ typedef long int int64;
#ifndef HAVE_UINT64
typedef unsigned long int uint64;
#endif
+#define INT64CONST(x) (x##L)
+#define UINT64CONST(x) (x##UL)
#elif defined(HAVE_LONG_LONG_INT_64)
/* We have working support for "long long int", use that */
@@ -294,20 +296,13 @@ typedef long long int int64;
#ifndef HAVE_UINT64
typedef unsigned long long int uint64;
#endif
+#define INT64CONST(x) (x##LL)
+#define UINT64CONST(x) (x##ULL)
#else
/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
#error must have a working 64-bit integer datatype
#endif
-/* Decide if we need to decorate 64-bit constants */
-#ifdef HAVE_LL_CONSTANTS
-#define INT64CONST(x) ((int64) x##LL)
-#define UINT64CONST(x) ((uint64) x##ULL)
-#else
-#define INT64CONST(x) ((int64) x)
-#define UINT64CONST(x) ((uint64) x)
-#endif
-
/* snprintf format strings to use for 64-bit integers */
#define INT64_FORMAT "%" INT64_MODIFIER "d"
#define UINT64_FORMAT "%" INT64_MODIFIER "u"
@@ -335,14 +330,18 @@ typedef unsigned PG_INT128_TYPE uint128;
#define PG_UINT16_MAX (0xFFFF)
#define PG_INT32_MIN (-0x7FFFFFFF-1)
#define PG_INT32_MAX (0x7FFFFFFF)
-#define PG_UINT32_MAX (0xFFFFFFFF)
+#define PG_UINT32_MAX (0xFFFFFFFFU)
#define PG_INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
#define PG_INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
#define PG_UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
/* Max value of size_t might also be missing if we don't have stdint.h */
#ifndef SIZE_MAX
-#define SIZE_MAX ((size_t) -1)
+#if SIZEOF_SIZE_T == 8
+#define SIZE_MAX PG_UINT64_MAX
+#else
+#define SIZE_MAX PG_UINT32_MAX
+#endif
#endif
/* Select timestamp representation (float8 or int64) */
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 7dbfa90bf49..a152371e61b 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -333,10 +333,6 @@
/* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ
-/* Define to 1 if constants of type 'long long int' should have the suffix LL.
- */
-#undef HAVE_LL_CONSTANTS
-
/* Define to 1 if the system has the type `locale_t'. */
#undef HAVE_LOCALE_T
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index 0e17ccbb405..65085d7d313 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -217,12 +217,6 @@
/* Define to 1 if you have the `z' library (-lz). */
/* #undef HAVE_LIBZ */
-/* Define to 1 if constants of type 'long long int' should have the suffix LL.
- */
-#if (_MSC_VER > 1200)
-#define HAVE_LL_CONSTANTS 1
-#endif
-
/* Define to 1 if the system has the type `locale_t'. */
#define HAVE_LOCALE_T 1
@@ -231,7 +225,7 @@
/* Define to 1 if `long long int' works and is 64 bits. */
#if (_MSC_VER > 1200)
-#define HAVE_LONG_LONG_INT_64
+#define HAVE_LONG_LONG_INT_64 1
#endif
/* Define to 1 if you have the `mbstowcs_l' function. */