aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-12-18 14:45:12 -0500
committerNick Mathewson <nickm@torproject.org>2013-01-16 22:29:39 -0500
commit5e06c4ee327b848f59578bc7d838cf34188ff6fd (patch)
tree8fdbf5a924438af68506ca8bdbe0697deca0ab1c /src/common/compat.h
parent739e83ca694411c318d868e0838238b4e3d9b5eb (diff)
downloadtor-5e06c4ee327b848f59578bc7d838cf34188ff6fd.tar
tor-5e06c4ee327b848f59578bc7d838cf34188ff6fd.tar.gz
When building with MSVC, call every enum bitfield unsigned
Fixes bug 7305.
Diffstat (limited to 'src/common/compat.h')
-rw-r--r--src/common/compat.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common/compat.h b/src/common/compat.h
index 9c544fa30..86ea0c41d 100644
--- a/src/common/compat.h
+++ b/src/common/compat.h
@@ -132,6 +132,17 @@ extern INLINE double U64_TO_DBL(uint64_t x) {
#define DBL_TO_U64(x) ((uint64_t) (x))
#endif
+#if defined(_MSC_VER)
+/* XXXX024 we should instead have a more general check for "Is enum signed?"*/
+#define ENUM_BF(t) unsigned
+#else
+/** Wrapper for having a bitfield of an enumerated type. Where possible, we
+ * just use the enumerated type (so the compiler can help us and notice
+ * problems), but if enumerated types are unsigned, we must use unsigned,
+ * so that the loss of precision doesn't make large values negative. */
+#define ENUM_BF(t) t
+#endif
+
/* GCC has several useful attributes. */
#if defined(__GNUC__) && __GNUC__ >= 3
#define ATTR_NORETURN __attribute__((noreturn))