]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Add configure checks for portability assumptions 251/head
authorTom Yu <tlyu@mit.edu>
Mon, 9 Feb 2015 20:02:20 +0000 (15:02 -0500)
committerTom Yu <tlyu@mit.edu>
Mon, 9 Feb 2015 20:02:20 +0000 (15:02 -0500)
Check a few portability assumptions:

* Integers are two's complement.  Testing that the bitwise complement
  of the representation of -1 is zero is sufficient, because C99
  6.2.6.2 only allows sign and magnitude, one's complement, and two's
  complement as representations.

* Integer values with sign bit one and value bits zero are valid and
  not trap representations.  C99 6.2.6.2 allows such a value to be a
  trap representation.  Testing that the declared integer value bounds
  are asymmetric in magnitude is sufficient.

* Conversion of an unsigned integer value that is not representable in
  the corresponding signed type preserves the bit pattern.  C99
  6.3.1.3 says this is implementation-defined, or raises an
  implementation-defined signal.  Exhaustively checking for the
  desired behavior is prohibitive, so this spot check will have to do.

* Bytes are 8 bits

src/configure.in

index 58e6e54ca7c6e47ad6bbd146832f64e85e739bd3..1a79ee2a424d821ece12bca077646d08b75cc9c8 100644 (file)
@@ -22,6 +22,40 @@ AC_SUBST(KRB5_VERSION)
 
 AC_REQUIRE_CPP
 
+AC_CACHE_CHECK([whether integers are two's complement],
+  [krb5_cv_ints_twos_compl],
+  [AC_COMPILE_IFELSE(
+    [AC_LANG_BOOL_COMPILE_TRY(
+[#include <limits.h>
+],
+       [/* Basic two's complement check */
+         ~(-1) == 0 && ~(-1L) == 0L &&
+         /* Check that values with sign bit 1 and value bits 0 are valid */
+         -(INT_MIN + 1) == INT_MAX && -(LONG_MIN + 1) == LONG_MAX &&
+         /* Check that unsigned-to-signed conversions preserve bit patterns */
+         (int)((unsigned int)INT_MAX + 1) == INT_MIN &&
+         (long)((unsigned long)LONG_MAX + 1) == LONG_MIN])],
+    [krb5_cv_ints_twos_compl=yes],
+    [krb5_cv_ints_twos_compl=no])])
+
+if test "$krb5_cv_ints_twos_compl" = "no"; then
+  AC_MSG_ERROR([integers are not two's complement])
+fi
+
+AC_CACHE_CHECK([whether CHAR_BIT is 8],
+  [krb5_cv_char_bit_8],
+  [AC_PREPROC_IFELSE([AC_LANG_SOURCE(
+[[#include <limits.h>
+#if CHAR_BIT != 8
+  #error CHAR_BIT != 8
+#endif
+]])],
+    [krb5_cv_char_bit_8=yes], [krb5_cv_char_bit_8=no])])
+
+if test "$krb5_cv_char_bit_8" = "no"; then
+  AC_MSG_ERROR([CHAR_BIT is not 8])
+fi
+
 AC_CACHE_CHECK(if va_copy is available, krb5_cv_va_copy,
 [AC_LINK_IFELSE([AC_LANG_SOURCE([
 #include <stdarg.h>