/pidgin/main: 965839bfe169: Mxit: fix invalid cast alignment war...

Tomasz Wasilczyk twasilczyk at pidgin.im
Wed Apr 2 22:33:57 EDT 2014


Changeset: 965839bfe169c74a46cab2d91d0db7726c71cc18
Author:	 Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date:	 2014-04-03 04:33 +0200
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/965839bfe169

Description:

Mxit: fix invalid cast alignment warnings

diffstat:

 libpurple/protocols/mxit/chunk.c    |  16 ++++++++++++----
 libpurple/protocols/mxit/chunk.h    |   3 ++-
 libpurple/protocols/mxit/protocol.c |  11 ++++++-----
 3 files changed, 20 insertions(+), 10 deletions(-)

diffs (69 lines):

diff --git a/libpurple/protocols/mxit/chunk.c b/libpurple/protocols/mxit/chunk.c
--- a/libpurple/protocols/mxit/chunk.c
+++ b/libpurple/protocols/mxit/chunk.c
@@ -170,9 +170,13 @@ static int get_int8( const char* chunkda
  */
 static int get_int16( const char* chunkdata, short* value )
 {
-	*value = ntohs( *( (const short*) chunkdata ) );	/* host byte-order */
+	gint16 value_v;
 
-	return sizeof( short );
+	memcpy(&value_v, chunkdata, sizeof(value_v));
+
+	*value = ntohs(value_v); /* host byte-order */
+
+	return sizeof(value_v);
 }
 
 /*------------------------------------------------------------------------
@@ -184,9 +188,13 @@ static int get_int16( const char* chunkd
  */
 static int get_int32( const char* chunkdata, int* value )
 {
-	*value = ntohl( *( (const int*) chunkdata ) );	/* host byte-order */
+	gint32 value_v;
 
-	return sizeof( int );
+	memcpy(&value_v, chunkdata, sizeof(value_v));
+
+	*value = ntohl(value_v); /* host byte-order */
+
+	return sizeof(value_v);
 }
 
 #if	0
diff --git a/libpurple/protocols/mxit/chunk.h b/libpurple/protocols/mxit/chunk.h
--- a/libpurple/protocols/mxit/chunk.h
+++ b/libpurple/protocols/mxit/chunk.h
@@ -84,7 +84,8 @@ static inline void set_chunk_type( gchar
 
 static inline guint32 chunk_length( gchar* chunkheader )
 {
-	guint32 length = *( (const guint32*) &chunkheader[1] );
+	guint32 length;
+	memcpy(&length, &chunkheader[1], sizeof(guint32));
 	return htonl( length );
 }
 
diff --git a/libpurple/protocols/mxit/protocol.c b/libpurple/protocols/mxit/protocol.c
--- a/libpurple/protocols/mxit/protocol.c
+++ b/libpurple/protocols/mxit/protocol.c
@@ -2093,11 +2093,12 @@ static void mxit_parse_cmd_msgevent( str
  */
 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);
 }
 
 



More information about the Commits mailing list