diff options
author | Nick Mathewson <nickm@torproject.org> | 2012-12-18 14:45:12 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-01-16 22:29:39 -0500 |
commit | 5e06c4ee327b848f59578bc7d838cf34188ff6fd (patch) | |
tree | 8fdbf5a924438af68506ca8bdbe0697deca0ab1c /src/common | |
parent | 739e83ca694411c318d868e0838238b4e3d9b5eb (diff) | |
download | tor-5e06c4ee327b848f59578bc7d838cf34188ff6fd.tar.gz tor-5e06c4ee327b848f59578bc7d838cf34188ff6fd.zip |
When building with MSVC, call every enum bitfield unsigned
Fixes bug 7305.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.h | 11 | ||||
-rw-r--r-- | src/common/crypto.c | 2 | ||||
-rw-r--r-- | src/common/tortls.c | 15 | ||||
-rw-r--r-- | src/common/util.c | 3 |
4 files changed, 23 insertions, 8 deletions
diff --git a/src/common/compat.h b/src/common/compat.h index 9c544fa309..86ea0c41d4 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 39f5a4a642..ed8d457d45 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 af3059a02d..1e01815095 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 b0055d6c78..7fcf69e128 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", |