]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Ensure that uint8_t is unsigned char
authorTaylor Yu <catalyst@torproject.org>
Fri, 26 May 2017 21:04:52 +0000 (17:04 -0400)
committerTaylor Yu <catalyst@torproject.org>
Mon, 19 Jun 2017 18:28:36 +0000 (14:28 -0400)
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.

changes/bug22410 [new file with mode: 0644]
configure.ac

diff --git a/changes/bug22410 b/changes/bug22410
new file mode 100644 (file)
index 0000000..678a26d
--- /dev/null
@@ -0,0 +1,4 @@
+  o Minor bugfixes (portability):
+    - Check at configure time whether uint8_t is unsigned char.  Lots
+      of existing code already assumes this, and there could be strict
+      aliasing issues if they aren't the same type.  Fixes #22410.
index 0c673d033da52b98b2b280bf5fb452ca8cc008b8..e8b35e8ce74ae180a67cc8392f6bf4adfa06e87f 100644 (file)
@@ -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 <stdint.h>
+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,