/pidgin/main: d9fdd45925ec: Fix some of invalid alignment warnings
Tomasz Wasilczyk
twasilczyk at pidgin.im
Wed Apr 2 18:47:21 EDT 2014
Changeset: d9fdd45925eca666399cc8ed1f4df2a570911b6f
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-03 00:47 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/d9fdd45925ec
Description:
Fix some of invalid alignment warnings
diffstat:
libpurple/plugins/tcl/tcl_glib.c | 3 +-
libpurple/protocols/bonjour/bonjour_ft.c | 7 ++-
libpurple/protocols/bonjour/jabber.c | 46 ++++++++++++----------
libpurple/protocols/gg/resolver-purple.c | 20 ++++----
libpurple/protocols/irc/dcc_send.c | 4 +-
libpurple/protocols/jabber/disco.c | 14 +++--
libpurple/protocols/jabber/google/jingleinfo.c | 14 +++--
libpurple/protocols/msn/directconn.c | 12 +++--
libpurple/protocols/msn/msnutils.c | 54 ++++++++++++++++---------
libpurple/protocols/msn/p2p.c | 8 +-
libpurple/protocols/msn/slpcall.c | 18 +++++--
libpurple/protocols/msn/tlv.c | 2 +-
libpurple/protocols/msn/tlv.h | 2 +-
13 files changed, 121 insertions(+), 83 deletions(-)
diffs (truncated from 528 to 300 lines):
diff --git a/libpurple/plugins/tcl/tcl_glib.c b/libpurple/plugins/tcl/tcl_glib.c
--- a/libpurple/plugins/tcl/tcl_glib.c
+++ b/libpurple/plugins/tcl/tcl_glib.c
@@ -224,7 +224,8 @@ static gboolean tcl_file_callback(GIOCha
return TRUE;
tfh->pending |= mask;
- fev = (struct tcl_file_event *)ckalloc(sizeof(struct tcl_file_event));
+ /* ckalloc returns memory "suitably aligned for any use" */
+ fev = (gpointer)ckalloc(sizeof(struct tcl_file_event));
memset(fev, 0, sizeof(struct tcl_file_event));
fev->header.proc = tcl_file_event_callback;
fev->fd = tfh->fd;
diff --git a/libpurple/protocols/bonjour/bonjour_ft.c b/libpurple/protocols/bonjour/bonjour_ft.c
--- a/libpurple/protocols/bonjour/bonjour_ft.c
+++ b/libpurple/protocols/bonjour/bonjour_ft.c
@@ -541,6 +541,7 @@ xep_cmp_addr(const char *host, const cha
{
#if defined(AF_INET6) && defined(HAVE_GETADDRINFO)
struct addrinfo hint, *res = NULL;
+ common_sockaddr_t addr;
int ret;
memset(&hint, 0, sizeof(hint));
@@ -550,9 +551,11 @@ xep_cmp_addr(const char *host, const cha
ret = getaddrinfo(host, NULL, &hint, &res);
if(ret)
goto out;
+ memcpy(&addr, res->ai_addr, sizeof(addr));
- if(res->ai_family != AF_INET6 ||
- !IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)res->ai_addr)->sin6_addr)) {
+ if (res->ai_family != AF_INET6 ||
+ !IN6_IS_ADDR_LINKLOCAL(&addr.in6.sin6_addr))
+ {
freeaddrinfo(res);
goto out;
}
diff --git a/libpurple/protocols/bonjour/jabber.c b/libpurple/protocols/bonjour/jabber.c
--- a/libpurple/protocols/bonjour/jabber.c
+++ b/libpurple/protocols/bonjour/jabber.c
@@ -705,14 +705,14 @@ static void
}
static int
-start_serversocket_listening(int port, int socket, struct sockaddr *addr, size_t addr_size, gboolean ip6, gboolean allow_port_fallback)
+start_serversocket_listening(int port, int socket, common_sockaddr_t *addr, size_t addr_size, gboolean ip6, gboolean allow_port_fallback)
{
int ret_port = port;
purple_debug_info("bonjour", "Attempting to bind IPv%d socket to port %d.\n", ip6 ? 6 : 4, port);
/* Try to use the specified port - if it isn't available, use a random port */
- if (bind(socket, addr, addr_size) != 0) {
+ if (bind(socket, &addr->sa, addr_size) != 0) {
purple_debug_info("bonjour", "Unable to bind to specified "
"port %i: %s\n", port, g_strerror(errno));
@@ -723,12 +723,12 @@ start_serversocket_listening(int port, i
}
#ifdef PF_INET6
if (ip6)
- ((struct sockaddr_in6 *) addr)->sin6_port = 0;
+ addr->in6.sin6_port = 0;
else
#endif
- ((struct sockaddr_in *) addr)->sin_port = 0;
+ addr->in.sin_port = 0;
- if (bind(socket, addr, addr_size) != 0) {
+ if (bind(socket, &addr->sa, addr_size) != 0) {
purple_debug_error("bonjour", "Unable to bind IPv%d socket to port: %s\n", ip6 ? 6 : 4, g_strerror(errno));
return -1;
}
@@ -774,16 +774,17 @@ bonjour_jabber_start(BonjourJabber *jdat
#ifdef PF_INET6
if (jdata->socket6 != -1) {
- struct sockaddr_in6 addr6;
+ common_sockaddr_t addr6;
#ifdef IPV6_V6ONLY
int on = 1;
setsockopt(jdata->socket6, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
#endif
- memset(&addr6, 0, sizeof(addr6));
- addr6.sin6_family = AF_INET6;
- addr6.sin6_port = htons(jdata->port);
- addr6.sin6_addr = in6addr_any;
- ipv6_port = start_serversocket_listening(jdata->port, jdata->socket6, (struct sockaddr *) &addr6, sizeof(addr6), TRUE, TRUE);
+ memset(&addr6, 0, sizeof(addr6));
+ addr6.in6.sin6_family = AF_INET6;
+ addr6.in6.sin6_port = htons(jdata->port);
+ addr6.in6.sin6_addr = in6addr_any;
+ ipv6_port = start_serversocket_listening(jdata->port,
+ jdata->socket6, &addr6, sizeof(addr6), TRUE, TRUE);
/* Open a watcher in the socket we have just opened */
if (ipv6_port > 0) {
jdata->watcher_id6 = purple_input_add(jdata->socket6, PURPLE_INPUT_READ, _server_socket_handler, jdata);
@@ -796,11 +797,12 @@ bonjour_jabber_start(BonjourJabber *jdat
}
#endif
if (jdata->socket != -1) {
- struct sockaddr_in addr4;
+ common_sockaddr_t addr4;
memset(&addr4, 0, sizeof(addr4));
- addr4.sin_family = AF_INET;
- addr4.sin_port = htons(jdata->port);
- ipv4_port = start_serversocket_listening(jdata->port, jdata->socket, (struct sockaddr *) &addr4, sizeof(addr4), FALSE, ipv6_port != -1);
+ addr4.in.sin_family = AF_INET;
+ addr4.in.sin_port = htons(jdata->port);
+ ipv4_port = start_serversocket_listening(jdata->port, jdata->socket,
+ &addr4, sizeof(addr4), FALSE, ipv6_port != -1);
/* Open a watcher in the socket we have just opened */
if (ipv4_port > 0) {
jdata->watcher_id = purple_input_add(jdata->socket, PURPLE_INPUT_READ, _server_socket_handler, jdata);
@@ -1367,7 +1369,7 @@ bonjour_jabber_get_local_ips(int fd)
#ifdef HAVE_GETIFADDRS /* This is required for IPv6 */
{
struct ifaddrs *ifap, *ifa;
- struct sockaddr *addr;
+ common_sockaddr_t addr;
char addrstr[INET6_ADDRSTRLEN];
ret = getifaddrs(&ifap);
@@ -1381,23 +1383,25 @@ bonjour_jabber_get_local_ips(int fd)
if (!(ifa->ifa_flags & IFF_RUNNING) || (ifa->ifa_flags & IFF_LOOPBACK) || ifa->ifa_addr == NULL)
continue;
- addr = ifa->ifa_addr;
+ memcpy(&addr, ifa->ifa_addr, sizeof(addr));
address_text = NULL;
- switch (addr->sa_family) {
+ switch (addr.sa.sa_family) {
case AF_INET:
- address_text = inet_ntop(addr->sa_family, &((struct sockaddr_in *)addr)->sin_addr,
+ address_text = inet_ntop(addr.sa.sa_family,
+ &addr.in.sin_addr,
addrstr, sizeof(addrstr));
break;
#ifdef PF_INET6
case AF_INET6:
- address_text = inet_ntop(addr->sa_family, &((struct sockaddr_in6 *)addr)->sin6_addr,
+ address_text = inet_ntop(addr.sa.sa_family,
+ &addr.in6.sin6_addr,
addrstr, sizeof(addrstr));
break;
#endif
}
if (address_text != NULL) {
- if (addr->sa_family == AF_INET)
+ if (addr.sa.sa_family == AF_INET)
ips = g_slist_append(ips, g_strdup(address_text));
else
ips = g_slist_prepend(ips, g_strdup(address_text));
diff --git a/libpurple/protocols/gg/resolver-purple.c b/libpurple/protocols/gg/resolver-purple.c
--- a/libpurple/protocols/gg/resolver-purple.c
+++ b/libpurple/protocols/gg/resolver-purple.c
@@ -89,28 +89,28 @@ void ggp_resolver_purple_cb(GSList *host
ipv4_count = 0;
while (hosts && (hosts = g_slist_delete_link(hosts, hosts))) {
- const struct sockaddr *addr = hosts->data;
+ common_sockaddr_t addr;
char dst[INET6_ADDRSTRLEN];
- if (addr->sa_family == AF_INET6) {
- inet_ntop(addr->sa_family,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
+ memcpy(&addr, hosts->data, sizeof(addr));
+
+ if (addr.sa.sa_family == AF_INET6) {
+ inet_ntop(addr.sa.sa_family, &addr.in6.sin6_addr,
dst, sizeof(dst));
purple_debug_misc("gg", "ggp_resolver_purple_cb "
"ipv6 (ignore): %s\n", dst);
- } else if (addr->sa_family == AF_INET) {
- const struct in_addr addr_ipv4 =
- ((struct sockaddr_in *) addr)->sin_addr;
- inet_ntop(addr->sa_family, &addr_ipv4,
+ } else if (addr.sa.sa_family == AF_INET) {
+ inet_ntop(addr.sa.sa_family, &addr.in.sin_addr,
dst, sizeof(dst));
purple_debug_misc("gg", "ggp_resolver_purple_cb "
"ipv4: %s\n", dst);
g_assert(ipv4_count < all_count);
- addresses[ipv4_count++] = addr_ipv4;
+ addresses[ipv4_count++] = addr.in.sin_addr;
} else {
purple_debug_warning("gg", "ggp_resolver_purple_cb "
- "unexpected sa_family: %d\n", addr->sa_family);
+ "unexpected sa_family: %d\n",
+ addr.sa.sa_family);
}
g_free(hosts->data);
diff --git a/libpurple/protocols/irc/dcc_send.c b/libpurple/protocols/irc/dcc_send.c
--- a/libpurple/protocols/irc/dcc_send.c
+++ b/libpurple/protocols/irc/dcc_send.c
@@ -199,12 +199,14 @@ static void irc_dccsend_send_read(gpoint
xd->rxlen += len;
while (1) {
+ gint32 val;
size_t acked;
if (xd->rxlen < 4)
break;
- acked = ntohl(*((gint32 *)xd->rxqueue));
+ memcpy(&val, xd->rxqueue, sizeof(val));
+ acked = ntohl(val);
xd->rxlen -= 4;
if (xd->rxlen) {
diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -436,18 +436,20 @@ jabber_disco_stun_lookup_cb(GSList *host
}
if (hosts && g_slist_next(hosts)) {
- struct sockaddr *addr = g_slist_next(hosts)->data;
+ common_sockaddr_t addr;
char dst[INET6_ADDRSTRLEN];
int port;
- if (addr->sa_family == AF_INET6) {
- inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
+ memcpy(&addr, g_slist_next(hosts)->data, sizeof(addr));
+
+ if (addr.sa.sa_family == AF_INET6) {
+ inet_ntop(addr.sa.sa_family, &addr.in6.sin6_addr,
dst, sizeof(dst));
- port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
+ port = ntohs(addr.in6.sin6_port);
} else {
- inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
+ inet_ntop(addr.sa.sa_family, &addr.in.sin_addr,
dst, sizeof(dst));
- port = ntohs(((struct sockaddr_in *) addr)->sin_port);
+ port = ntohs(addr.in.sin_port);
}
if (js->stun_ip)
diff --git a/libpurple/protocols/jabber/google/jingleinfo.c b/libpurple/protocols/jabber/google/jingleinfo.c
--- a/libpurple/protocols/jabber/google/jingleinfo.c
+++ b/libpurple/protocols/jabber/google/jingleinfo.c
@@ -37,18 +37,20 @@ jabber_google_stun_lookup_cb(GSList *hos
}
if (hosts && g_slist_next(hosts)) {
- struct sockaddr *addr = g_slist_next(hosts)->data;
+ common_sockaddr_t addr;
char dst[INET6_ADDRSTRLEN];
int port;
- if (addr->sa_family == AF_INET6) {
- inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
+ memcpy(&addr, g_slist_next(hosts)->data, sizeof(addr));
+
+ if (addr.sa.sa_family == AF_INET6) {
+ inet_ntop(addr.sa.sa_family, &addr.in6.sin6_addr,
dst, sizeof(dst));
- port = ntohs(((struct sockaddr_in6 *) addr)->sin6_port);
+ port = ntohs(addr.in6.sin6_port);
} else {
- inet_ntop(addr->sa_family, &((struct sockaddr_in *) addr)->sin_addr,
+ inet_ntop(addr.sa.sa_family, &addr.in.sin_addr,
dst, sizeof(dst));
- port = ntohs(((struct sockaddr_in *) addr)->sin_port);
+ port = ntohs(addr.in.sin_port);
}
if (js->stun_ip)
diff --git a/libpurple/protocols/msn/directconn.c b/libpurple/protocols/msn/directconn.c
--- a/libpurple/protocols/msn/directconn.c
+++ b/libpurple/protocols/msn/directconn.c
@@ -84,12 +84,13 @@ msn_dc_calculate_nonce_hash(MsnDirectCon
static void
msn_dc_generate_nonce(MsnDirectConn *dc)
{
- guint32 *nonce;
int i;
- nonce = (guint32 *)&dc->nonce;
- for (i = 0; i < 4; i++)
- nonce[i] = rand();
+ for (i = 0; i < 4; i++) {
+ guint32 randval = g_random_int();
+ memcpy(dc->nonce + sizeof(guint32) * i,
+ &randval, sizeof(guint32));
+ }
msn_dc_calculate_nonce_hash(dc->nonce_type, dc->nonce, sizeof(dc->nonce), dc->nonce_hash);
@@ -661,7 +662,8 @@ msn_dc_recv_cb(gpointer data, gint fd, P
/* Wait for packet length */
More information about the Commits
mailing list