From 027614c263b4a1ae6f74e3470723f97331af8baa Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Fri, 26 May 2017 17:04:52 -0400 Subject: Ensure that uint8_t is unsigned char Many places in our code assume that uint8_t is the same type as unsigned char. Test this assumption in the configure script. This is important because of the privileged aliasing properties of character types in C. Fixes #22410. --- configure.ac | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 0c673d033d..e8b35e8ce7 100644 --- a/configure.ac +++ b/configure.ac @@ -1552,6 +1552,24 @@ if test "$tor_cv_sign_extend" != "no"; then [Define to 1 iff right-shifting a negative value performs sign-extension]) fi +# Is uint8_t the same type as unsigned char? +AC_CACHE_CHECK([whether uint8_t is the same type as unsigned char], tor_cv_uint8_uchar, +[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ +#include +extern uint8_t c; +unsigned char c;]])], + [tor_cv_uint8_uchar=yes], + [tor_cv_uint8_uchar=no], + [tor_cv_uint8_uchar=cross])]) + +if test "$tor_cv_uint8_uchar" = "cross"; then + AC_MSG_NOTICE([Cross-compiling: we'll assume that uint8_t is the same type as unsigned char]) +fi + +if test "$tor_cv_uint8_uchar" = "no"; then + AC_MSG_ERROR([We assume that uint8_t is the same type as unsigned char, but your compiler disagrees.]) +fi + # Whether we should use the dmalloc memory allocation debugging library. AC_MSG_CHECKING(whether to use dmalloc (debug memory allocation library)) AC_ARG_WITH(dmalloc, -- cgit v1.2.3-54-g00ecf