/pidgin/main: 7cd76ebbe8d1: MXit: Refactor dump_bytes() not to u...

Andrew Victor andrew.victor at mxit.com
Tue Apr 2 19:25:56 EDT 2013


Changeset: 7cd76ebbe8d15f0c08e88fec80ced5c624c1c9f0
Author:	 Andrew Victor <andrew.victor at mxit.com>
Date:	 2013-04-03 01:25 +0200
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/7cd76ebbe8d1

Description:

MXit: Refactor dump_bytes() not to use a C99-style variable length array.

* Removes warning when compiling for InstantBird:
  protocol.c:103:1: warning: ISO C90 forbids variable length array ?request? [-Wvla]

* Characters > 0x7E should also be treated as non-printable.

diffstat:

 libpurple/protocols/mxit/protocol.c |  21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diffs (41 lines):

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
@@ -100,26 +100,27 @@ void mxit_strip_domain( char* username )
  */
 void dump_bytes( struct MXitSession* session, const char* buf, int len )
 {
-	char		msg[( len * 3 ) + 1];
-	int			i;
-
-	memset( msg, 0x00, sizeof( msg ) );
+	char*	msg	= g_malloc0( len + 1 );
+	int		i;
 
 	for ( i = 0; i < len; i++ ) {
-		if ( buf[i] == CP_REC_TERM )		/* record terminator */
+		char ch	= buf[i];
+
+		if ( ch == CP_REC_TERM )		/* record terminator */
 			msg[i] = '!';
-		else if ( buf[i] == CP_FLD_TERM )	/* field terminator */
+		else if ( ch == CP_FLD_TERM )	/* field terminator */
 			msg[i] = '^';
-		else if ( buf[i] == CP_PKT_TERM )	/* packet terminator */
+		else if ( ch == CP_PKT_TERM )	/* packet terminator */
 			msg[i] = '@';
-		else if ( buf[i] < 0x20 )
+		else if ( ( ch < 0x20 ) || ( ch > 0x7E ) )		/* non-printable character */
 			msg[i] = '_';
 		else
-			msg[i] = buf[i];
-
+			msg[i] = ch;
 	}
 
 	purple_debug_info( MXIT_PLUGIN_ID, "DUMP: '%s'\n", msg );
+
+	g_free( msg );
 }
 
 



More information about the Commits mailing list