diff --git a/include/m_ctype.h b/include/m_ctype.h
index deecf560170e367d1f8289a08e9614af67ac46a9..c357f0673588e2c133ca47dd9ada753849f6a58f 100644
--- a/include/m_ctype.h
+++ b/include/m_ctype.h
@@ -196,7 +196,7 @@ typedef struct my_charset_handler_st
   
   /* Charset dependant snprintf() */
   int  (*snprintf)(struct charset_info_st *, char *to, uint n, const char *fmt,
-		   ...) ATTRIBUTE_FORMAT(printf, 4, 5);
+		   ...) ATTRIBUTE_FORMAT_FPTR(printf, 4, 5);
   int  (*long10_to_str)(struct charset_info_st *, char *to, uint n, int radix,
 			long int val);
   int (*longlong10_to_str)(struct charset_info_st *, char *to, uint n,
diff --git a/include/my_global.h b/include/my_global.h
index 579379e75067469e4debadb7ccb16499b08514b3..39947735f3cfad4bdead8a5f9e46aa639f96368f 100644
--- a/include/my_global.h
+++ b/include/my_global.h
@@ -563,9 +563,6 @@ typedef unsigned short ushort;
 #ifndef __attribute__
 # if !defined(__GNUC__)
 #  define __attribute__(A)
-# elif defined (__QNXNTO__)
-   /* qcc defines GNUC */
-#  define __attribute__(A)
 # elif GCC_VERSION < 2008
 #  define __attribute__(A)
 # elif defined(__cplusplus) && GCC_VERSION < 3004
@@ -582,6 +579,19 @@ typedef unsigned short ushort;
 # define ATTRIBUTE_FORMAT(style, m, n) __attribute__((format(style, m, n)))
 #endif
 
+/*
+
+   __attribute__((format(...))) on a function pointer is not supported
+   until  gcc 3.1
+*/
+#ifndef ATTRIBUTE_FORMAT_FPTR
+# if (GCC_VERSION >= 3001)
+#  define ATTRIBUTE_FORMAT_FPTR(style, m, n) ATTRIBUTE_FORMAT(style, m, n)
+# else
+#  define ATTRIBUTE_FORMAT_FPTR(style, m, n)
+# endif /* GNUC >= 3.1 */
+#endif
+
 /*
   Wen using the embedded library, users might run into link problems,
   duplicate declaration of __cxa_pure_virtual, solved by declaring it a
diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result
index 7dbff4beca5d91566fd71ee0bf3a086ac1fd1816..1053b1918fb03b5047231eb23a09b117d6583972 100644
--- a/mysql-test/r/mysql.result
+++ b/mysql-test/r/mysql.result
@@ -76,6 +76,16 @@ c_cp932
 | >a   <               | 0123456789 |      4 | 
 | >abcd<               |            |      4 | 
 +----------------------+------------+--------+
++-------------------+
+| __ta帽g猫 脩茫m茅      |
++-------------------+
+| John Doe          | 
++-------------------+
++-------------------+
+| John Doe          |
++-------------------+
+| __ta帽g猫 脩茫m茅      | 
++-------------------+
 +------+------+---------------------------+
 | i    | j    | k                         |
 +------+------+---------------------------+
diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test
index 9e3eabf474be536e7e4ee7597bbe87603768152e..f3296e6f7068a58c76f82b02331ac52487d35551 100644
--- a/mysql-test/t/mysql.test
+++ b/mysql-test/t/mysql.test
@@ -62,6 +62,12 @@ drop table t1;
 #
 --exec $MYSQL -t test -e "create table t1 (col1 binary(4), col2 varchar(10), col3 int); insert into t1 values ('a', 'b', 123421),('a ', '0123456789', 4), ('abcd', '', 4); select concat('>',col1,'<'), col2, col3 from t1; drop table t1;" 2>&1
 
+#
+# Bug#17939 Wrong table format when using UTF8 strings
+#
+--exec $MYSQL --default-character-set=utf8 --table -e "SELECT 'John Doe' as '__ta帽g猫 脩茫m茅'" 2>&1
+--exec $MYSQL --default-character-set=utf8 --table -e "SELECT '__ta帽g猫 脩茫m茅' as 'John Doe'" 2>&1
+
 #
 # Bug#18265 -- mysql client: No longer right-justifies numeric columns
 #
diff --git a/scripts/mysqlhotcopy.sh b/scripts/mysqlhotcopy.sh
index bf53aa78e15bb78a43e6fd1038c98ba760d608d9..61cd59457d13e685906cfb61e880e3f8c2ad2a22 100644
--- a/scripts/mysqlhotcopy.sh
+++ b/scripts/mysqlhotcopy.sh
@@ -263,6 +263,7 @@ my $hc_locks = "";
 my $hc_tables = "";
 my $num_tables = 0;
 my $num_files = 0;
+my $raid_dir_regex = '[A-Za-z0-9]{2}';
 
 foreach my $rdb ( @db_desc ) {
     my $db = $rdb->{src};
@@ -294,7 +295,7 @@ foreach my $rdb ( @db_desc ) {
     my @raid_dir = ();
 
     while ( defined( my $name = readdir DBDIR ) ) {
-	if ( $name =~ /^\d\d$/ && -d "$db_dir/$name" ) {
+	if ( $name =~ /^$raid_dir_regex$/ && -d "$db_dir/$name" ) {
 	    push @raid_dir, $name;
 	}
 	else {
@@ -602,7 +603,7 @@ sub copy_files {
 	# add recursive option for scp
 	$cp.= " -r" if $^O =~ /m^(solaris|linux|freebsd|darwin)$/ && $method =~ /^scp\b/;
 
-	my @non_raid = map { "'$_'" } grep { ! m:/\d{2}/[^/]+$: } @$files;
+	my @non_raid = map { "'$_'" } grep { ! m:/$raid_dir_regex/[^/]+$: } @$files;
 
 	# add files to copy and the destination directory
 	safe_system( $cp, @non_raid, "'$target'" ) if (@non_raid);
@@ -810,7 +811,7 @@ sub get_raid_dirs {
 
     my %dirs = ();
     foreach my $f ( @$r_files ) {
-	if ( $f =~ m:^(\d\d)/: ) {
+	if ( $f =~ m:^($raid_dir_regex)/: ) {
 	    $dirs{$1} = 1;
 	}
     }
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 599bca6cbe12a78fb7b976fc3551495f8f8cdf1f..30f494a48ac7a2f525bdcf36b4ad55365abb62ee 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -5549,7 +5549,7 @@ ST_FIELD_INFO partitions_fields_info[]=
 ST_FIELD_INFO variables_fields_info[]=
 {
   {"Variable_name", 80, MYSQL_TYPE_STRING, 0, 0, "Variable_name"},
-  {"Value", 255, MYSQL_TYPE_STRING, 0, 0, "Value"},
+  {"Value", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, "Value"},
   {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
 };