8000 Make [U]INT64CONST safe for use in #if conditions. · koderP/postgres@dd344de · GitHub
[go: up one dir, main page]

Skip to content

Commit dd344de

Browse files
committed
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 2e70d6b 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
1 parent 074985b commit dd344de

File tree

5 files changed

+10
-88
lines changed

5 files changed

+10
-88
lines changed

configure

Lines changed: 0 additions & 54 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -25392,60 +25392,6 @@ cat >>confdefs.h <<_ACEOF
2539225392
_ACEOF
2539325393

2539425394

25395-
25396-
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
25397-
cat >conftest.$ac_ext <<_ACEOF
25398-
/* confdefs.h. */
25399-
_ACEOF
25400-
cat confdefs.h >>conftest.$ac_ext
25401-
cat >>conftest.$ac_ext <<_ACEOF
25402-
/* end confdefs.h. */
25403-
25404-
#define INT64CONST(x) x##LL
25405-
long long int foo = INT64CONST(0x1234567890123456);
25406-
25407-
int
25408-
main ()
25409-
{
25410-
25411-
;
25412-
return 0;
8000 25413-
}
25414-
_ACEOF
25415-
rm -f conftest.$ac_objext
25416-
if { (ac_try="$ac_compile"
25417-
case "(($ac_try" in
25418-
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
25419-
*) ac_try_echo=$ac_try;;
25420-
esac
25421-
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
25422-
$as_echo "$ac_try_echo") >&5
25423-
(eval "$ac_compile") 2>conftest.er1
25424-
ac_status=$?
25425-
grep -v '^ *+' conftest.er1 >conftest.err
25426-
rm -f conftest.er1
25427-
cat conftest.err >&5
25428-
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
25429-
(exit $ac_status); } && {
25430-
test -z "$ac_c_werror_flag" ||
25431-
test ! -s conftest.err
25432-
} && test -s conftest.$ac_objext; then
25433-
25434-
cat >>confdefs.h <<\_ACEOF
25435-
#define HAVE_LL_CONSTANTS 1
25436-
_ACEOF
25437-
25438-
else
25439-
$as_echo "$as_me: failed program was:" >&5
25440-
sed 's/^/| /' conftest.$ac_ext >&5
25441-
25442-
25443-
fi
25444-
25445-
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
25446-
fi
25447-
25448-
2544925395
# If we found "long int" is 64 bits, assume snprintf handles it. If
2545025396
# we found we need to use "long long int", better check. We cope with
2545125397
# snprintfs that use %lld, %qd, or %I64d as the format. If none of these

configure.in

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,19 +1667,6 @@ fi
16671667
AC_D 8000 EFINE_UNQUOTED(PG_INT64_TYPE, $pg_int64_type,
16681668
[Define to the name of a signed 64-bit integer type.])
16691669

1670-
dnl If we need to use "long long int", figure out whether nnnLL notation works.
1671-
1672-
if test x"$HAVE_LONG_LONG_INT_64" = xyes ; then
1673-
AC_TRY_COMPILE([
1674-
#define INT64CONST(x) x##LL
1675-
long long int foo = INT64CONST(0x1234567890123456);
1676-
],
1677-
[],
1678-
[AC_DEFINE(HAVE_LL_CONSTANTS, 1, [Define to 1 if constants of type 'long long int' should have the suffix LL.])],
1679-
[])
1680-
fi
1681-
1682-
16831670
# If we found "long int" is 64 bits, assume snprintf handles it. If
16841671
# we found we need to use "long long int", better check. We cope with
16851672
# snprintfs that use %lld, %qd, or %I64d as the format. If none of these

src/include/c.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ typedef long int int64;
272272
#ifndef HAVE_UINT64
273273
typedef unsigned long int uint64;
274274
#endif
275+
#define INT64CONST(x) (x##L)
276+
#define UINT64CONST(x) (x##UL)
275277
#elif defined(HAVE_LONG_LONG_INT_64)
276278
/* We have working support for "long long int", use that */
277279

@@ -281,23 +283,20 @@ typedef long long int int64;
281283
#ifndef HAVE_UINT64
282284
typedef unsigned long long int uint64;
283285
#endif
286+
#define INT64CONST(x) (x##LL)
287+
#define UINT64CONST(x) (x##ULL)
284288
#else
285289
/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
286290
#error must have a working 64-bit integer datatype
287291
#endif
288292

289-
/* Decide if we need to decorate 64-bit constants */
290-
#ifdef HAVE_LL_CONSTANTS
291-
#define INT64CONST(x) ((int64) x##LL)
292-
#define UINT64CONST(x) ((uint64) x##ULL)
293-
#else
294-
#define INT64CONST(x) ((int64) x)
295-
#define UINT64CONST(x) ((uint64) x)
296-
#endif
297-
298293
/* Max value of size_t might be missing if we don't have stdint.h */
299294
#ifndef SIZE_MAX
300-
#define SIZE_MAX ((size_t) -1)
295+
#if SIZEOF_SIZE_T == 8
296+
#define SIZE_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
297+
#else
298+
#define SIZE_MAX (0xFFFFFFFFU)
299+
#endif
301300
#endif
302301

303302
/* Select timestamp representation (float8 or int64) */

src/include/pg_config.h.in

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,6 @@
326326
/* Define to 1 if you have the `z' library (-lz). */
327327
#undef HAVE_LIBZ
328328

329-
/* Define to 1 if constants of type 'long long int' should have the suffix LL.
330-
*/
331-
#undef HAVE_LL_CONSTANTS
332-
333329
/* Define to 1 if the system has the type `locale_t'. */
334330
#undef HAVE_LOCALE_T
335331

src/include/pg_config.h.win32

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,6 @@
232232
/* Define to 1 if you have the `z' library (-lz). */
233233
/* #undef HAVE_LIBZ */
234234

235-
/* Define to 1 if constants of type 'long long int' should have the suffix LL.
236-
*/
237-
#if (_MSC_VER > 1200)
238-
#define HAVE_LL_CONSTANTS 1
239-
#endif
240-
241235
/* Define to 1 if the system has the type `locale_t'. */
242236
#define HAVE_LOCALE_T 1
243237

@@ -246,7 +240,7 @@
246240

247241
/* Define to 1 if `long long int' works and is 64 bits. */
248242
#if (_MSC_VER > 1200)
249-
#define HAVE_LONG_LONG_INT_64
243+
#define HAVE_LONG_LONG_INT_64 1
250244
#endif
251245

252246
/* Define to 1 if you have the `mbstowcs_l' function. */

0 commit comments

Comments
 (0)
0