pidgin/pidgin

Mxit: fix invalid cast alignment warnings

2014-04-03, Tomasz Wasilczyk
965839bfe169
Parents 0c337fe8f655
Children 54694ef14d46
Mxit: fix invalid cast alignment warnings
--- a/libpurple/protocols/mxit/chunk.c Thu Apr 03 04:23:35 2014 +0200
+++ b/libpurple/protocols/mxit/chunk.c Thu Apr 03 04:33:49 2014 +0200
@@ -170,9 +170,13 @@
*/
static int get_int16( const char* chunkdata, short* value )
{
- *value = ntohs( *( (const short*) chunkdata ) ); /* host byte-order */
+ gint16 value_v;
+
+ memcpy(&value_v, chunkdata, sizeof(value_v));
- return sizeof( short );
+ *value = ntohs(value_v); /* host byte-order */
+
+ return sizeof(value_v);
}
/*------------------------------------------------------------------------
@@ -184,9 +188,13 @@
*/
static int get_int32( const char* chunkdata, int* value )
{
- *value = ntohl( *( (const int*) chunkdata ) ); /* host byte-order */
+ gint32 value_v;
+
+ memcpy(&value_v, chunkdata, sizeof(value_v));
- return sizeof( int );
+ *value = ntohl(value_v); /* host byte-order */
+
+ return sizeof(value_v);
}
#if 0
--- a/libpurple/protocols/mxit/chunk.h Thu Apr 03 04:23:35 2014 +0200
+++ b/libpurple/protocols/mxit/chunk.h Thu Apr 03 04:33:49 2014 +0200
@@ -84,7 +84,8 @@
static inline guint32 chunk_length( gchar* chunkheader )
{
- guint32 length = *( (const guint32*) &chunkheader[1] );
+ guint32 length;
+ memcpy(&length, &chunkheader[1], sizeof(guint32));
return htonl( length );
}
--- a/libpurple/protocols/mxit/protocol.c Thu Apr 03 04:23:35 2014 +0200
+++ b/libpurple/protocols/mxit/protocol.c Thu Apr 03 04:33:49 2014 +0200
@@ -2093,11 +2093,12 @@
*/
static int get_chunk_len( const char* chunkdata )
{
- int* sizeptr;
-
- sizeptr = (int*) &chunkdata[1]; /* we skip the first byte (type field) */
-
- return ntohl( *sizeptr );
+ guint32 size_val;
+
+ /* we skip the first byte (type field) */
+ memcpy(&size_val, &chunkdata[1], sizeof(size_val));
+
+ return ntohl(size_val);
}