aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/common/compat.h11
-rw-r--r--src/common/crypto.c2
-rw-r--r--src/common/tortls.c15
-rw-r--r--src/common/util.c3
-rw-r--r--src/or/addressmap.c2
-rw-r--r--src/or/channel.h2
-rw-r--r--src/or/or.h28
7 files changed, 41 insertions, 22 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))
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 39f5a4a64..ed8d457d4 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1505,7 +1505,7 @@ struct crypto_digest_t {
SHA256_CTX sha2; /**< state for SHA256 */
} d; /**< State for the digest we're using. Only one member of the
* union is usable, depending on the value of <b>algorithm</b>. */
- digest_algorithm_t algorithm : 8; /**< Which algorithm is in use? */
+ ENUM_BF(digest_algorithm_t) algorithm : 8; /**< Which algorithm is in use? */
};
/** Allocate and return a new digest object to compute SHA1 digests.
diff --git a/src/common/tortls.c b/src/common/tortls.c
index af3059a02..1e0181509 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -129,6 +129,12 @@ typedef struct tor_tls_context_t {
#define TOR_TLS_MAGIC 0x71571571
+typedef enum {
+ TOR_TLS_ST_HANDSHAKE, TOR_TLS_ST_OPEN, TOR_TLS_ST_GOTCLOSE,
+ TOR_TLS_ST_SENTCLOSE, TOR_TLS_ST_CLOSED, TOR_TLS_ST_RENEGOTIATE,
+ TOR_TLS_ST_BUFFEREVENT
+} tor_tls_state_t;
+
/** Holds a SSL object and its associated data. Members are only
* accessed from within tortls.c.
*/
@@ -138,12 +144,9 @@ struct tor_tls_t {
SSL *ssl; /**< An OpenSSL SSL object. */
int socket; /**< The underlying file descriptor for this TLS connection. */
char *address; /**< An address to log when describing this connection. */
- enum {
- TOR_TLS_ST_HANDSHAKE, TOR_TLS_ST_OPEN, TOR_TLS_ST_GOTCLOSE,
- TOR_TLS_ST_SENTCLOSE, TOR_TLS_ST_CLOSED, TOR_TLS_ST_RENEGOTIATE,
- TOR_TLS_ST_BUFFEREVENT
- } state : 3; /**< The current SSL state, depending on which operations have
- * completed successfully. */
+ ENUM_BF(tor_tls_state_t) state : 3; /**< The current SSL state,
+ * depending on which operations
+ * have completed successfully. */
unsigned int isServer:1; /**< True iff this is a server-side connection */
unsigned int wasV2Handshake:1; /**< True iff the original handshake for
* this connection used the updated version
diff --git a/src/common/util.c b/src/common/util.c
index b0055d6c7..7fcf69e12 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -4919,7 +4919,8 @@ tor_check_port_forwarding(const char *filename,
status = tor_spawn_background(filename, argv, NULL, &child_handle);
#endif
- tor_free((void*)argv);
+ tor_free_((void*)argv);
+ argv=NULL;
if (PROCESS_STATUS_ERROR == status) {
log_warn(LD_GENERAL, "Failed to start port forwarding helper %s",
diff --git a/src/or/addressmap.c b/src/or/addressmap.c
index f4c31295a..a7fc60a0a 100644
--- a/src/or/addressmap.c
+++ b/src/or/addressmap.c
@@ -45,7 +45,7 @@
typedef struct {
char *new_address;
time_t expires;
- addressmap_entry_source_t source:3;
+ ENUM_BF(addressmap_entry_source_t) source:3;
unsigned src_wildcard:1;
unsigned dst_wildcard:1;
short num_resolve_failures;
diff --git a/src/or/channel.h b/src/or/channel.h
index d2106551a..accc3dceb 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -142,7 +142,7 @@ struct channel_s {
* When we send CREATE cells along this connection, which half of the
* space should we use?
*/
- circ_id_type_t circ_id_type:2;
+ ENUM_BF(circ_id_type_t) circ_id_type:2;
/*
* Which circ_id do we try to use next on this connection? This is
* always in the range 0..1<<15-1.
diff --git a/src/or/or.h b/src/or/or.h
index 3a8e50c80..459e18e46 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1583,6 +1583,13 @@ typedef struct entry_connection_t {
} entry_connection_t;
+typedef enum {
+ DIR_SPOOL_NONE=0, DIR_SPOOL_SERVER_BY_DIGEST, DIR_SPOOL_SERVER_BY_FP,
+ DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP,
+ DIR_SPOOL_CACHED_DIR, DIR_SPOOL_NETWORKSTATUS,
+ DIR_SPOOL_MICRODESC, /* NOTE: if we add another entry, add another bit. */
+} dir_spool_source_t;
+
/** Subtype of connection_t for an "directory connection" -- that is, an HTTP
* connection to retrieve or serve directory material. */
typedef struct dir_connection_t {
@@ -1601,12 +1608,8 @@ typedef struct dir_connection_t {
* "spooling" of directory material to the outbuf. Otherwise, we'd have
* to append everything to the outbuf in one enormous chunk. */
/** What exactly are we spooling right now? */
- enum {
- DIR_SPOOL_NONE=0, DIR_SPOOL_SERVER_BY_DIGEST, DIR_SPOOL_SERVER_BY_FP,
- DIR_SPOOL_EXTRA_BY_DIGEST, DIR_SPOOL_EXTRA_BY_FP,
- DIR_SPOOL_CACHED_DIR, DIR_SPOOL_NETWORKSTATUS,
- DIR_SPOOL_MICRODESC, /* NOTE: if we add another entry, add another bit. */
- } dir_spool_src : 3;
+ ENUM_BF(dir_spool_source_t) dir_spool_src : 3;
+
/** If we're fetching descriptors, what router purpose shall we assign
* to them? */
uint8_t router_purpose;
@@ -1782,7 +1785,8 @@ typedef enum {
/** A reference-counted address policy rule. */
typedef struct addr_policy_t {
int refcnt; /**< Reference count */
- addr_policy_action_t policy_type:2;/**< What to do when the policy matches.*/
+ /** What to do when the policy matches.*/
+ ENUM_BF(addr_policy_action_t) policy_type:2;
unsigned int is_private:1; /**< True iff this is the pseudo-address,
* "private". */
unsigned int is_canonical:1; /**< True iff this policy is the canonical
@@ -1850,7 +1854,7 @@ typedef struct download_status_t {
* again? */
uint8_t n_download_failures; /**< Number of failures trying to download the
* most recent descriptor. */
- download_schedule_t schedule : 8;
+ ENUM_BF(download_schedule_t) schedule : 8;
} download_status_t;
/** If n_download_failures is this high, the download can never happen. */
@@ -2114,7 +2118,7 @@ typedef struct microdesc_t {
*/
time_t last_listed;
/** Where is this microdescriptor currently stored? */
- saved_location_t saved_location : 3;
+ ENUM_BF(saved_location_t) saved_location : 3;
/** If true, do not attempt to cache this microdescriptor on disk. */
unsigned int no_save : 1;
/** If true, this microdesc has an entry in the microdesc_map */
@@ -2362,8 +2366,8 @@ typedef enum {
/** A common structure to hold a v3 network status vote, or a v3 network
* status consensus. */
typedef struct networkstatus_t {
- networkstatus_type_t type : 8; /**< Vote, consensus, or opinion? */
- consensus_flavor_t flavor : 8; /**< If a consensus, what kind? */
+ ENUM_BF(networkstatus_type_t) type : 8; /**< Vote, consensus, or opinion? */
+ ENUM_BF(consensus_flavor_t) flavor : 8; /**< If a consensus, what kind? */
time_t published; /**< Vote only: Time when vote was written. */
time_t valid_after; /**< Time after which this vote or consensus applies. */
time_t fresh_until; /**< Time before which this is the most recent vote or
@@ -2846,7 +2850,7 @@ typedef struct origin_circuit_t {
/** Kludge to help us prevent the warn in bug #6475 and eventually
* debug why we are not seeing first hops in some cases. */
- path_state_t path_state : 2;
+ ENUM_BF(path_state_t) path_state : 2;
/** Set iff this is a hidden-service circuit which has timed out
* according to our current circuit-build timeout, but which has