/pidgin/main: 8b6b8a3b5039: Fix most of invalid alignment warnings
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Apr 3 07:31:15 EDT 2014
Changeset: 8b6b8a3b5039348f08ad7a689343dcfae5cf716c
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2014-04-03 13:31 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/8b6b8a3b5039
Description:
Fix most of invalid alignment warnings
diffstat:
libpurple/ciphers/aescipher.c | 5 ++-
libpurple/memorypool.c | 2 +-
libpurple/network.c | 59 +++++++++++++++++++++++-----------------
libpurple/ntlm.c | 17 ++++++----
libpurple/proxy.c | 47 +++++++++++++++----------------
libpurple/stun.c | 63 +++++++++++++++++++++++-------------------
6 files changed, 105 insertions(+), 88 deletions(-)
diffs (truncated from 512 to 300 lines):
diff --git a/libpurple/ciphers/aescipher.c b/libpurple/ciphers/aescipher.c
--- a/libpurple/ciphers/aescipher.c
+++ b/libpurple/ciphers/aescipher.c
@@ -483,8 +483,9 @@ purple_aes_cipher_encrypt(PurpleCipher *
input_padded = purple_aes_cipher_pad_pkcs7(input, in_len, &out_len);
if (out_len > out_size) {
- purple_debug_error("cipher-aes",
- "Output buffer too small (%d > %d)", out_len, out_size);
+ purple_debug_error("cipher-aes", "Output buffer too small (%"
+ G_GSIZE_FORMAT " > %" G_GSIZE_FORMAT ")",
+ out_len, out_size);
memset(input_padded, 0, out_len);
g_free(input_padded);
return -1;
diff --git a/libpurple/memorypool.c b/libpurple/memorypool.c
--- a/libpurple/memorypool.c
+++ b/libpurple/memorypool.c
@@ -137,7 +137,7 @@ purple_memory_pool_alloc_impl(PurpleMemo
}
mem = PURPLE_MEMORY_PADDED(blk->available_ptr, alignment);
- g_assert(mem + size < blk->end_ptr);
+ g_assert((guintptr)mem + size < (guintptr)blk->end_ptr);
g_assert(mem >= blk->available_ptr); /* gpointer overflow */
}
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -140,9 +140,9 @@ purple_network_get_public_ip(void)
const char *
purple_network_get_local_system_ip(int fd)
{
- char buffer[1024];
+ struct ifreq buffer[100];
+ guchar *it, *it_end;
static char ip[16];
- char *tmp;
struct ifconf ifc;
struct ifreq *ifr;
struct sockaddr_in *sinptr;
@@ -154,21 +154,26 @@ purple_network_get_local_system_ip(int f
source = socket(PF_INET,SOCK_STREAM, 0);
ifc.ifc_len = sizeof(buffer);
- ifc.ifc_req = (struct ifreq *)buffer;
+ ifc.ifc_req = buffer;
ioctl(source, SIOCGIFCONF, &ifc);
if (fd < 0)
close(source);
- tmp = buffer;
- while (tmp < buffer + ifc.ifc_len)
- {
- ifr = (struct ifreq *)tmp;
- tmp += HX_SIZE_OF_IFREQ(*ifr);
+ it = (guchar*)buffer;
+ it_end = it + ifc.ifc_len;
+ while (it < it_end) {
+ /* in this case "it" is:
+ * a) (struct ifreq)-aligned
+ * b) not aligned, because of OS quirks (see
+ * _SIZEOF_ADDR_IFREQ), so the OS should deal with it.
+ */
+ ifr = (struct ifreq *)(gpointer)it;
+ it += HX_SIZE_OF_IFREQ(*ifr);
if (ifr->ifr_addr.sa_family == AF_INET)
{
- sinptr = (struct sockaddr_in *)&ifr->ifr_addr;
+ sinptr = (struct sockaddr_in *)(gpointer)&ifr->ifr_addr;
if (sinptr->sin_addr.s_addr != lhost)
{
add = ntohl(sinptr->sin_addr.s_addr);
@@ -205,21 +210,22 @@ purple_network_get_all_local_system_ips(
int family = ifa->ifa_addr ? ifa->ifa_addr->sa_family : AF_UNSPEC;
char host[INET6_ADDRSTRLEN];
const char *tmp = NULL;
+ common_sockaddr_t *addr =
+ (common_sockaddr_t *)(gpointer)ifa->ifa_addr;
if ((family != AF_INET && family != AF_INET6) || ifa->ifa_flags & IFF_LOOPBACK)
continue;
if (family == AF_INET)
- tmp = inet_ntop(family, &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, host, sizeof(host));
+ tmp = inet_ntop(family, &addr->in.sin_addr, host, sizeof(host));
else {
- struct sockaddr_in6 *sockaddr = (struct sockaddr_in6 *)ifa->ifa_addr;
/* Peer-peer link-local communication is a big TODO. I am not sure
* how communicating link-local addresses is supposed to work, and
* it seems like it would require attempting the cartesian product
* of the local and remote interfaces to see if any match (eww).
*/
- if (!IN6_IS_ADDR_LINKLOCAL(&sockaddr->sin6_addr))
- tmp = inet_ntop(family, &sockaddr->sin6_addr, host, sizeof(host));
+ if (!IN6_IS_ADDR_LINKLOCAL(&addr->in6.sin6_addr))
+ tmp = inet_ntop(family, &addr->in6.sin6_addr, host, sizeof(host));
}
if (tmp != NULL)
result = g_list_prepend(result, g_strdup(tmp));
@@ -231,25 +237,28 @@ purple_network_get_all_local_system_ips(
#else /* HAVE_GETIFADDRS && HAVE_INET_NTOP */
GList *result = NULL;
int source = socket(PF_INET,SOCK_STREAM, 0);
- char buffer[1024];
- char *tmp;
+ struct ifreq buffer[100];
+ guchar *it, *it_end;
struct ifconf ifc;
struct ifreq *ifr;
ifc.ifc_len = sizeof(buffer);
- ifc.ifc_req = (struct ifreq *)buffer;
+ ifc.ifc_req = buffer;
ioctl(source, SIOCGIFCONF, &ifc);
close(source);
- tmp = buffer;
- while (tmp < buffer + ifc.ifc_len) {
+ it = (guchar*)buffer;
+ it_end = it + ifc.ifc_len;
+ while (it < it_end) {
char dst[INET_ADDRSTRLEN];
- ifr = (struct ifreq *)tmp;
- tmp += HX_SIZE_OF_IFREQ(*ifr);
+ /* alignment: see purple_network_get_local_system_ip */
+ ifr = (struct ifreq *)(gpointer)it;
+ it += HX_SIZE_OF_IFREQ(*ifr);
if (ifr->ifr_addr.sa_family == AF_INET) {
- struct sockaddr_in *sinptr = (struct sockaddr_in *)&ifr->ifr_addr;
+ struct sockaddr_in *sinptr =
+ (struct sockaddr_in *)(gpointer)&ifr->ifr_addr;
inet_ntop(AF_INET, &sinptr->sin_addr, dst,
sizeof(dst));
@@ -986,14 +995,14 @@ purple_network_ip_lookup_cb(GSList *host
}
if (hosts && g_slist_next(hosts)) {
- struct sockaddr *addr = g_slist_next(hosts)->data;
+ common_sockaddr_t *addr = g_slist_next(hosts)->data;
char dst[INET6_ADDRSTRLEN];
- if (addr->sa_family == AF_INET6) {
- inet_ntop(addr->sa_family, &((struct sockaddr_in6 *) addr)->sin6_addr,
+ if (addr->sa.sa_family == AF_INET6) {
+ inet_ntop(addr->sa.sa_family, &addr->in6.sin6_addr,
dst, sizeof(dst));
} 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));
}
diff --git a/libpurple/ntlm.c b/libpurple/ntlm.c
--- a/libpurple/ntlm.c
+++ b/libpurple/ntlm.c
@@ -121,7 +121,7 @@ purple_ntlm_gen_type1(const gchar *hostn
host_off = sizeof(struct type1_message);
dom_off = sizeof(struct type1_message) + hostnamelen;
msg = g_malloc0(sizeof(struct type1_message) + hostnamelen + domainlen);
- tmsg = (struct type1_message*)msg;
+ tmsg = (struct type1_message*)(gpointer)msg;
tmsg->protocol[0] = 'N';
tmsg->protocol[1] = 'T';
tmsg->protocol[2] = 'L';
@@ -149,19 +149,22 @@ guint8 *
purple_ntlm_parse_type2(const gchar *type2, guint32 *flags)
{
gsize retlen;
- struct type2_message *tmsg;
+ guchar *buff;
+ struct type2_message tmsg;
static guint8 nonce[8];
- tmsg = (struct type2_message*)purple_base64_decode(type2, &retlen);
- if (tmsg != NULL && retlen >= (sizeof(struct type2_message) - 1)) {
- memcpy(nonce, tmsg->nonce, 8);
+ buff = purple_base64_decode(type2, &retlen);
+
+ if (buff != NULL && retlen >= (sizeof(struct type2_message) - 1)) {
+ memcpy(&tmsg, buff, MIN(retlen, sizeof(tmsg)));
+ memcpy(nonce, tmsg.nonce, 8);
if (flags != NULL)
- *flags = GUINT16_FROM_LE(tmsg->flags);
+ *flags = GUINT16_FROM_LE(tmsg.flags);
} else {
purple_debug_error("ntlm", "Unable to parse type2 message - returning empty nonce.\n");
memset(nonce, 0, 8);
}
- g_free(tmsg);
+ g_free(buff);
return nonce;
}
diff --git a/libpurple/proxy.c b/libpurple/proxy.c
--- a/libpurple/proxy.c
+++ b/libpurple/proxy.c
@@ -748,14 +748,14 @@ clean_connect(gpointer data)
}
static void
-proxy_connect_udp_none(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
+proxy_connect_udp_none(PurpleProxyConnectData *connect_data, common_sockaddr_t *addr, socklen_t addrlen)
{
int flags;
purple_debug_info("proxy", "UDP Connecting to %s:%d with no proxy\n",
connect_data->host, connect_data->port);
- connect_data->fd = socket(addr->sa_family, SOCK_DGRAM, 0);
+ connect_data->fd = socket(addr->sa.sa_family, SOCK_DGRAM, 0);
if (connect_data->fd < 0)
{
purple_proxy_connect_data_disconnect_formatted(connect_data,
@@ -769,7 +769,7 @@ proxy_connect_udp_none(PurpleProxyConnec
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
- if (connect(connect_data->fd, addr, addrlen) != 0)
+ if (connect(connect_data->fd, &addr->sa, addrlen) != 0)
{
if ((errno == EINPROGRESS) || (errno == EINTR))
{
@@ -810,14 +810,14 @@ proxy_connect_udp_none(PurpleProxyConnec
}
static void
-proxy_connect_none(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
+proxy_connect_none(PurpleProxyConnectData *connect_data, common_sockaddr_t *addr, socklen_t addrlen)
{
int flags;
purple_debug_info("proxy", "Connecting to %s:%d with no proxy\n",
connect_data->host, connect_data->port);
- connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
+ connect_data->fd = socket(addr->sa.sa_family, SOCK_STREAM, 0);
if (connect_data->fd < 0)
{
purple_proxy_connect_data_disconnect_formatted(connect_data,
@@ -831,7 +831,7 @@ proxy_connect_none(PurpleProxyConnectDat
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
- if (connect(connect_data->fd, addr, addrlen) != 0)
+ if (connect(connect_data->fd, &addr->sa, addrlen) != 0)
{
if ((errno == EINPROGRESS) || (errno == EINTR))
{
@@ -1258,7 +1258,7 @@ http_canwrite(gpointer data, gint source
}
static void
-proxy_connect_http(PurpleProxyConnectData *connect_data, struct sockaddr *addr, socklen_t addrlen)
+proxy_connect_http(PurpleProxyConnectData *connect_data, common_sockaddr_t *addr, socklen_t addrlen)
{
int flags;
@@ -1268,7 +1268,7 @@ proxy_connect_http(PurpleProxyConnectDat
(purple_proxy_info_get_host(connect_data->gpi) ? purple_proxy_info_get_host(connect_data->gpi) : "(null)"),
purple_proxy_info_get_port(connect_data->gpi));
- connect_data->fd = socket(addr->sa_family, SOCK_STREAM, 0);
+ connect_data->fd = socket(addr->sa.sa_family, SOCK_STREAM, 0);
if (connect_data->fd < 0)
{
purple_proxy_connect_data_disconnect_formatted(connect_data,
@@ -1282,7 +1282,7 @@ proxy_connect_http(PurpleProxyConnectDat
fcntl(connect_data->fd, F_SETFD, FD_CLOEXEC);
#endif
- if (connect(connect_data->fd, addr, addrlen) != 0) {
+ if (connect(connect_data->fd, &addr->sa, addrlen) != 0) {
if (errno == EINPROGRESS || errno == EINTR) {
purple_debug_info("proxy", "HTTP connection in progress\n");
@@ -1335,7 +1335,7 @@ s4_host_resolved(GSList *hosts, gpointer
{
PurpleProxyConnectData *connect_data = data;
unsigned char packet[9];
- struct sockaddr *addr;
+ common_sockaddr_t *addr;
connect_data->query_data = NULL;
@@ -1359,7 +1359,7 @@ s4_host_resolved(GSList *hosts, gpointer
packet[1] = 0x01;
packet[2] = connect_data->port >> 8;
packet[3] = connect_data->port & 0xff;
- memcpy(packet + 4, &((struct sockaddr_in *)addr)->sin_addr.s_addr, 4);
+ memcpy(packet + 4, &addr->in.sin_addr.s_addr, 4);
packet[8] = 0x00;
g_free(addr);
More information about the Commits
mailing list