diff options
author | Nick Mathewson <nickm@torproject.org> | 2010-02-09 12:32:10 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2010-02-09 12:32:10 -0500 |
commit | c0d682686ad8df66b1f6680b1185853532f24429 (patch) | |
tree | 5f2bc651108569b0b1c034fd326ee958e62c4a39 | |
parent | 080e8f50f87fb7c0c099b1341173fa05c82a42e8 (diff) | |
download | tor-c0d682686ad8df66b1f6680b1185853532f24429.tar.gz tor-c0d682686ad8df66b1f6680b1185853532f24429.zip |
Make tor_addr_copy() conform to memcpy requirements
The src and dest of a memcpy() call aren't supposed to overlap,
but we were sometimes calling tor_addr_copy() as a no-op.
Also, tor_addr_assign was a redundant copy of tor_addr_copy(); this patch
removes it.
-rw-r--r-- | src/common/address.c | 9 | ||||
-rw-r--r-- | src/common/address.h | 1 | ||||
-rw-r--r-- | src/or/connection_edge.c | 4 | ||||
-rw-r--r-- | src/or/dns.c | 2 |
4 files changed, 5 insertions, 11 deletions
diff --git a/src/common/address.c b/src/common/address.c index 2fe013a2cd..7729f29147 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -760,6 +760,8 @@ tor_addr_from_in6(tor_addr_t *dest, const struct in6_addr *in6) void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src) { + if (src == dest) + return; tor_assert(src); tor_assert(dest); memcpy(dest, src, sizeof(tor_addr_t)); @@ -912,13 +914,6 @@ tor_dup_addr(const tor_addr_t *addr) return tor_strdup(buf); } -/** Copy the address in <b>src</b> to <b>dest</b> */ -void -tor_addr_assign(tor_addr_t *dest, const tor_addr_t *src) -{ - memcpy(dest, src, sizeof(tor_addr_t)); -} - /** Return a string representing the address <b>addr</b>. This string is * statically allocated, and must not be freed. Each call to * <b>fmt_addr</b> invalidates the last result of the function. This diff --git a/src/common/address.h b/src/common/address.h index 9480d64274..4d4c91075b 100644 --- a/src/common/address.h +++ b/src/common/address.h @@ -107,7 +107,6 @@ tor_addr_eq_ipv4h(const tor_addr_t *a, uint32_t u) int tor_addr_lookup(const char *name, uint16_t family, tor_addr_t *addr_out); char *tor_dup_addr(const tor_addr_t *addr) ATTR_MALLOC; -void tor_addr_assign(tor_addr_t *dest, const tor_addr_t *src); const char *fmt_addr(const tor_addr_t *addr); int get_interface_address6(int severity, sa_family_t family, tor_addr_t *addr); diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c index 8447853fc1..8bb6742dca 100644 --- a/src/or/connection_edge.c +++ b/src/or/connection_edge.c @@ -2607,7 +2607,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ) if (rh.command == RELAY_COMMAND_BEGIN_DIR) { tor_assert(or_circ); if (or_circ->p_conn && !tor_addr_is_null(&or_circ->p_conn->real_addr)) - tor_addr_assign(&n_stream->_base.addr, &or_circ->p_conn->real_addr); + tor_addr_copy(&n_stream->_base.addr, &or_circ->p_conn->real_addr); return connection_exit_connect_dir(n_stream); } @@ -2779,7 +2779,7 @@ connection_exit_connect_dir(edge_connection_t *exitconn) dirconn = dir_connection_new(AF_INET); - tor_addr_assign(&dirconn->_base.addr, &exitconn->_base.addr); + tor_addr_copy(&dirconn->_base.addr, &exitconn->_base.addr); dirconn->_base.port = 0; dirconn->_base.address = tor_strdup(exitconn->_base.address); dirconn->_base.type = CONN_TYPE_DIR; diff --git a/src/or/dns.c b/src/or/dns.c index 08bff763a3..c055c885b7 100644 --- a/src/or/dns.c +++ b/src/or/dns.c @@ -655,7 +655,7 @@ dns_resolve_impl(edge_connection_t *exitconn, int is_resolve, * know the answer. */ if (tor_addr_from_str(&addr, exitconn->_base.address) >= 0) { if (tor_addr_family(&addr) == AF_INET) { - tor_addr_assign(&exitconn->_base.addr, &addr); + tor_addr_copy(&exitconn->_base.addr, &addr); exitconn->address_ttl = DEFAULT_DNS_TTL; return 1; } else { |