From 3f2210c06445535f3beae31a8cecb3ae73c1d236 Mon Sep 17 00:00:00 2001
From: "serg@serg.mylan" <>
Date: Thu, 19 Aug 2004 03:02:09 +0200
Subject: [PATCH] after merge fixes

---
 .bzrignore                       |  1 +
 mysql-test/mysql-test-run.sh     |  1 -
 mysql-test/r/alter_table.result  |  4 ++--
 mysql-test/r/func_math.result    | 32 ++++++++++++++++----------------
 mysql-test/r/grant.result        | 19 +++++++++++++++++++
 mysql-test/r/having.result       |  6 +++---
 mysql-test/r/heap.result         |  2 +-
 mysql-test/r/myisam.result       |  9 +++++++++
 mysql-test/r/type_uint.result    |  4 ++++
 mysql-test/t/having.test         |  6 +++---
 mysql-test/t/heap.test           |  2 +-
 mysql-test/t/type_timestamp.test | 11 -----------
 sql-common/client.c              |  2 +-
 sql/field.cc                     | 29 +++++++----------------------
 sql/field.h                      |  8 ++++----
 sql/protocol.cc                  | 10 +++++-----
 sql/sql_string.h                 |  8 ++++++++
 sql/sql_yacc.yy                  |  2 +-
 strings/my_vsnprintf.c           | 30 +++++++++++++-----------------
 19 files changed, 98 insertions(+), 88 deletions(-)

diff --git a/.bzrignore b/.bzrignore
index 31e06858b8..9542cfe875 100644
--- a/.bzrignore
+++ b/.bzrignore
@@ -907,3 +907,4 @@ ndb/test/tools/hugoScanUpdate
 ndb/test/tools/ndb_cpcc
 ndb/test/tools/restart
 ndb/test/tools/verify_index
+EXCEPTIONS-CLIENT
diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh
index 56425a6080..261da9c7a6 100644
--- a/mysql-test/mysql-test-run.sh
+++ b/mysql-test/mysql-test-run.sh
@@ -613,7 +613,6 @@ show_failed_diff ()
     echo "http://www.mysql.com/doc/en/Reporting_mysqltest_bugs.html"
     echo "to find the reason to this problem and how to report this."
     echo ""
-    echo "Test $1 failed!"
   fi
 }
 
diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result
index c920cc706b..e85ad30356 100644
--- a/mysql-test/r/alter_table.result
+++ b/mysql-test/r/alter_table.result
@@ -478,7 +478,7 @@ alter table t1 drop key a;
 drop table t1;
 create table t1 (a int);
 alter table t1 rename to `t1\\`;
-Incorrect table name 't1\\'
+ERROR 42000: Incorrect table name 't1\\'
 rename table t1 to `t1\\`;
-Incorrect table name 't1\\'
+ERROR 42000: Incorrect table name 't1\\'
 drop table t1;
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result
index 12eef4aa88..90aa04515d 100644
--- a/mysql-test/r/func_math.result
+++ b/mysql-test/r/func_math.result
@@ -43,7 +43,7 @@ Warnings:
 Note	1003	select abs(-(10)) AS `abs(-10)`,sign(-(5)) AS `sign(-5)`,sign(5) AS `sign(5)`,sign(0) AS `sign(0)`
 select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
 log(exp(10))	exp(log(sqrt(10))*2)	log(-1)	log(NULL)	log(1,1)	log(3,9)	log(-1,2)	log(NULL,2)
-10.000000	10.000000	NULL	NULL	NULL	2.000000	NULL	NULL
+10	10	NULL	NULL	NULL	2	NULL	NULL
 explain extended select log(exp(10)),exp(log(sqrt(10))*2),log(-1),log(NULL),log(1,1),log(3,9),log(-1,2),log(NULL,2);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -51,7 +51,7 @@ Warnings:
 Note	1003	select log(exp(10)) AS `log(exp(10))`,exp((log(sqrt(10)) * 2)) AS `exp(log(sqrt(10))*2)`,log(-(1)) AS `log(-1)`,log(NULL) AS `log(NULL)`,log(1,1) AS `log(1,1)`,log(3,9) AS `log(3,9)`,log(-(1),2) AS `log(-1,2)`,log(NULL,2) AS `log(NULL,2)`
 select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
 ln(exp(10))	exp(ln(sqrt(10))*2)	ln(-1)	ln(0)	ln(NULL)
-10.000000	10.000000	NULL	NULL	NULL
+10	10	NULL	NULL	NULL
 explain extended select ln(exp(10)),exp(ln(sqrt(10))*2),ln(-1),ln(0),ln(NULL);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -59,7 +59,7 @@ Warnings:
 Note	1003	select ln(exp(10)) AS `ln(exp(10))`,exp((ln(sqrt(10)) * 2)) AS `exp(ln(sqrt(10))*2)`,ln(-(1)) AS `ln(-1)`,ln(0) AS `ln(0)`,ln(NULL) AS `ln(NULL)`
 select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
 log2(8)	log2(15)	log2(-2)	log2(0)	log2(NULL)
-3.000000	3.906891	NULL	NULL	NULL
+3	3.9068905956085	NULL	NULL	NULL
 explain extended select log2(8),log2(15),log2(-2),log2(0),log2(NULL);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -67,7 +67,7 @@ Warnings:
 Note	1003	select log2(8) AS `log2(8)`,log2(15) AS `log2(15)`,log2(-(2)) AS `log2(-2)`,log2(0) AS `log2(0)`,log2(NULL) AS `log2(NULL)`
 select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
 log10(100)	log10(18)	log10(-4)	log10(0)	log10(NULL)
-2.000000	1.255273	NULL	NULL	NULL
+2	1.2552725051033	NULL	NULL	NULL
 explain extended select log10(100),log10(18),log10(-4),log10(0),log10(NULL);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -75,7 +75,7 @@ Warnings:
 Note	1003	select log10(100) AS `log10(100)`,log10(18) AS `log10(18)`,log10(-(4)) AS `log10(-4)`,log10(0) AS `log10(0)`,log10(NULL) AS `log10(NULL)`
 select pow(10,log10(10)),power(2,4);
 pow(10,log10(10))	power(2,4)
-10.000000	16.000000
+10	16
 explain extended select pow(10,log10(10)),power(2,4);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
@@ -90,35 +90,35 @@ id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 Warnings:
 Note	1003	select sql_no_cache rand(999999) AS `rand(999999)`,rand() AS `rand()`
-select pi(),sin(pi()/2),cos(pi()/2),abs(tan(pi())),cot(1),asin(1),acos(0),atan(1);
-pi()	sin(pi()/2)	cos(pi()/2)	abs(tan(pi()))	cot(1)	asin(1)	acos(0)	atan(1)
-3.141593	1.000000	0.000000	0.000000	0.64209262	1.570796	1.570796	0.785398
-explain extended select pi(),sin(pi()/2),cos(pi()/2),abs(tan(pi())),cot(1),asin(1),acos(0),atan(1);
+select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
+pi()	format(sin(pi()/2),6)	format(cos(pi()/2),6)	format(abs(tan(pi())),6)	format(cot(1),6)	format(asin(1),6)	format(acos(0),6)	format(atan(1),6)
+3.141593	1.000000	0.000000	0.000000	0.642093	1.570796	1.570796	0.785398
+explain extended select pi(),format(sin(pi()/2),6),format(cos(pi()/2),6),format(abs(tan(pi())),6),format(cot(1),6),format(asin(1),6),format(acos(0),6),format(atan(1),6);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
 Warnings:
-Note	1003	select pi() AS `pi()`,sin((pi() / 2)) AS `sin(pi()/2)`,cos((pi() / 2)) AS `cos(pi()/2)`,abs(tan(pi())) AS `abs(tan(pi()))`,(1 / tan(1)) AS `cot(1)`,asin(1) AS `asin(1)`,acos(0) AS `acos(0)`,atan(1) AS `atan(1)`
+Note	1003	select pi() AS `pi()`,format(sin((pi() / 2)),6) AS `format(sin(pi()/2),6)`,format(cos((pi() / 2)),6) AS `format(cos(pi()/2),6)`,format(abs(tan(pi())),6) AS `format(abs(tan(pi())),6)`,format((1 / tan(1)),6) AS `format(cot(1),6)`,format(asin(1),6) AS `format(asin(1),6)`,format(acos(0),6) AS `format(acos(0),6)`,format(atan(1),6) AS `format(atan(1),6)`
 select degrees(pi()),radians(360);
 degrees(pi())	radians(360)
 180	6.2831853071796
 SELECT ACOS(1.0);
 ACOS(1.0)
-0.000000
+0
 SELECT ASIN(1.0);
 ASIN(1.0)
-1.570796
+1.5707963267949
 SELECT ACOS(0.2*5.0);
 ACOS(0.2*5.0)
-0.000000
+0
 SELECT ACOS(0.5*2.0);
 ACOS(0.5*2.0)
-0.000000
+0
 SELECT ASIN(0.8+0.2);
 ASIN(0.8+0.2)
-1.570796
+1.5707963267949
 SELECT ASIN(1.2-0.2);
 ASIN(1.2-0.2)
-1.570796
+1.5707963267949
 explain extended select degrees(pi()),radians(360);
 id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
diff --git a/mysql-test/r/grant.result b/mysql-test/r/grant.result
index aa6c0c3f50..35b9034980 100644
--- a/mysql-test/r/grant.result
+++ b/mysql-test/r/grant.result
@@ -229,3 +229,22 @@ GRANT SELECT (
 REVOKE SELECT (кол) ON бд.таб FROM юзер@localhost;
 DROP DATABASE бд;
 SET NAMES latin1;
+insert into mysql.user (host, user) values ('localhost', 'test11');
+insert into mysql.db (host, db, user, select_priv) values 
+('localhost', 'a%', 'test11', 'Y'), ('localhost', 'ab%', 'test11', 'Y');
+alter table mysql.db order by db asc;
+flush privileges;
+show grants for test11@localhost;
+Grants for test11@localhost
+GRANT USAGE ON *.* TO 'test11'@'localhost'
+GRANT SELECT ON `ab%`.* TO 'test11'@'localhost'
+GRANT SELECT ON `a%`.* TO 'test11'@'localhost'
+alter table mysql.db order by db desc;
+flush privileges;
+show grants for test11@localhost;
+Grants for test11@localhost
+GRANT USAGE ON *.* TO 'test11'@'localhost'
+GRANT SELECT ON `ab%`.* TO 'test11'@'localhost'
+GRANT SELECT ON `a%`.* TO 'test11'@'localhost'
+delete from mysql.user where user='test11';
+delete from mysql.db where user='test11';
diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result
index e2196fa62a..f7e0bbf3e2 100644
--- a/mysql-test/r/having.result
+++ b/mysql-test/r/having.result
@@ -90,17 +90,17 @@ drop table t1;
 CREATE TABLE t1 (
 `id` bigint(20) NOT NULL default '0',
 `description` text
-) TYPE=MyISAM;
+) ENGINE=MyISAM;
 CREATE TABLE t2 (
 `id` bigint(20) NOT NULL default '0',
 `description` varchar(20)
-) TYPE=MyISAM;
+) ENGINE=MyISAM;
 INSERT INTO t1  VALUES (1, 'test');
 INSERT INTO t2 VALUES (1, 'test');
 CREATE TABLE t3 (
 `id`       bigint(20) NOT NULL default '0',
 `order_id` bigint(20) NOT NULL default '0'
-) TYPE=MyISAM;
+) ENGINE=MyISAM;
 select
 a.id, a.description,
 count(b.id) as c 
diff --git a/mysql-test/r/heap.result b/mysql-test/r/heap.result
index b7f44e6e19..c49c9abb36 100644
--- a/mysql-test/r/heap.result
+++ b/mysql-test/r/heap.result
@@ -222,7 +222,7 @@ CREATE TABLE `job_titles` (
 `job_title` char(18) NOT NULL default '',
 PRIMARY KEY  (`job_title_id`),
 UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
-) TYPE=HEAP;
+) ENGINE=HEAP;
 SELECT MAX(job_title_id) FROM job_titles;
 MAX(job_title_id)
 NULL
diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result
index 9a123729c4..354675cd4d 100644
--- a/mysql-test/r/myisam.result
+++ b/mysql-test/r/myisam.result
@@ -529,3 +529,12 @@ show keys from t1;
 Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
 t1	1	a	1	a	NULL	NULL	NULL	NULL	YES	HASH	
 drop table t1,t2;
+create table t1 ( a tinytext, b char(1), index idx (a(1),b) );
+insert into t1 values (null,''), (null,'');
+explain select count(*) from t1 where a is null;
+id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+1	SIMPLE	t1	ref	idx	idx	4	const	1	Using where
+select count(*) from t1 where a is null;
+count(*)
+2
+drop table t1;
diff --git a/mysql-test/r/type_uint.result b/mysql-test/r/type_uint.result
index 07eb47faa7..d8edf9085b 100644
--- a/mysql-test/r/type_uint.result
+++ b/mysql-test/r/type_uint.result
@@ -5,8 +5,12 @@ insert into t1 values (1);
 insert into t1 values (-1);
 Warnings:
 Warning	1264	Data truncated; out of range for column 'this' at row 1
+insert into t1 values ('5000000000');
+Warnings:
+Warning	1265	Data truncated for column 'this' at row 1
 select * from t1;
 this
 1
 0
+4294967295
 drop table t1;
diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index 4c0a4bacd5..870f57a448 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -84,12 +84,12 @@ drop table t1;
 CREATE TABLE t1 (
   `id` bigint(20) NOT NULL default '0',
   `description` text
-) TYPE=MyISAM;
+) ENGINE=MyISAM;
 
 CREATE TABLE t2 (
   `id` bigint(20) NOT NULL default '0',
   `description` varchar(20)
-) TYPE=MyISAM;
+) ENGINE=MyISAM;
 
 INSERT INTO t1  VALUES (1, 'test');
 INSERT INTO t2 VALUES (1, 'test');
@@ -97,7 +97,7 @@ INSERT INTO t2 VALUES (1, 'test');
 CREATE TABLE t3 (
   `id`       bigint(20) NOT NULL default '0',
   `order_id` bigint(20) NOT NULL default '0'
-) TYPE=MyISAM;
+) ENGINE=MyISAM;
 
 select
 	a.id, a.description,
diff --git a/mysql-test/t/heap.test b/mysql-test/t/heap.test
index 56442dfd6f..37fc5a4322 100644
--- a/mysql-test/t/heap.test
+++ b/mysql-test/t/heap.test
@@ -159,7 +159,7 @@ CREATE TABLE `job_titles` (
   `job_title` char(18) NOT NULL default '',
   PRIMARY KEY  (`job_title_id`),
   UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
-) TYPE=HEAP;
+) ENGINE=HEAP;
 
 SELECT MAX(job_title_id) FROM job_titles;
 
diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test
index a04e46081e..9b3abc9f15 100644
--- a/mysql-test/t/type_timestamp.test
+++ b/mysql-test/t/type_timestamp.test
@@ -234,14 +234,3 @@ alter table t1 add i int default 10;
 select * from t1;
 drop table t1;
 
-#
-# Test for bug #4491, TIMESTAMP(19) should be possible to create and not
-# only read in 4.0
-#
-create table t1 (ts timestamp(19));
-show create table t1;
-set TIMESTAMP=1000000000;
-insert into t1 values ();
-select * from t1;
-drop table t1;
-
diff --git a/sql-common/client.c b/sql-common/client.c
index 738904657c..17cc8ed0a8 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1037,7 +1037,7 @@ void mysql_read_default_options(struct st_mysql_options *options,
 	    options->client_flag&= ~CLIENT_LOCAL_FILES;
 	  break;
 	case 22:
-	  options->client_flag&= CLIENT_LOCAL_FILES;
+	  options->client_flag&= ~CLIENT_LOCAL_FILES;
           break;
 	case 23:  /* replication probe */
 #ifndef TO_BE_DELETED
diff --git a/sql/field.cc b/sql/field.cc
index 4458c14160..caf4e22f4c 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -4268,24 +4268,21 @@ int Field_string::store(const char *from,uint length,CHARSET_INFO *cs)
   Store double value in Field_string or Field_varstring.
 
   SYNOPSIS
-    store_double_in_string_field()
-    field         field to store value in
-    field_length  number of characters in the field
+    store(double nr)
     nr            number
 
   DESCRIPTION
     Pretty prints double number into field_length characters buffer.
 */
 
-static int store_double_in_string_field(Field_str *field, uint32 field_length,
-                                         double nr)
+int Field_str::store(double nr)
 {
   bool use_scientific_notation=TRUE;
   char buff[DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE];
   int length;
-  if (field_length < 32 && nr > 1)
+  if (field_length < 32 && nr > 1) // TODO: negative numbers
   {
-    if (field->ceiling == 0)
+    if (ceiling == 0)
     {
       static double e[]= {1e1, 1e2, 1e4, 1e8, 1e16 };
       double p= 1;
@@ -4294,23 +4291,17 @@ static int store_double_in_string_field(Field_str *field, uint32 field_length,
         if (field_length & j)
           p*= e[i];
       }
-      field->ceiling= p-1;
+      ceiling= p-1;
     }
-    use_scientific_notation= (field->ceiling < nr);
+    use_scientific_notation= (ceiling < nr);
   }
   length= sprintf(buff, "%-.*g",
                   use_scientific_notation ? max(0,field_length-5) : field_length,
                   nr);
   DBUG_ASSERT(length <= field_length);
-  return field->store(buff, (uint) length);
+  return store((const char *)buff, (uint) length, charset());
 }
 
-int Field_string::store(double nr)
- {
-  return store_double_in_string_field(this, field_length, nr);
-}
-
-
 int Field_string::store(longlong nr)
 {
   char buff[64];
@@ -4479,12 +4470,6 @@ int Field_varstring::store(const char *from,uint length,CHARSET_INFO *cs)
 }
 
 
-int Field_varstring::store(double nr)
-{
-  return store_double_in_string_field(this, field_length, nr);
-}
-
-
 int Field_varstring::store(longlong nr)
 {
   char buff[64];
diff --git a/sql/field.h b/sql/field.h
index 694d1efa28..fe06cd96f1 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -336,21 +336,23 @@ public:
 class Field_str :public Field {
 protected:
   CHARSET_INFO *field_charset;
-public:
   double ceiling; // for ::store(double nr)
+public:
   Field_str(char *ptr_arg,uint32 len_arg, uchar *null_ptr_arg,
 	    uchar null_bit_arg, utype unireg_check_arg,
 	    const char *field_name_arg,
 	    struct st_table *table_arg,CHARSET_INFO *charset)
     :Field(ptr_arg, len_arg, null_ptr_arg, null_bit_arg,
 	   unireg_check_arg, field_name_arg, table_arg), ceiling(0.0)
-    { 
+    {
       field_charset=charset;
       if (charset->state & MY_CS_BINSORT)
         flags|=BINARY_FLAG;
     }
   Item_result result_type () const { return STRING_RESULT; }
   uint decimals() const { return NOT_FIXED_DEC; }
+  int  store(double nr);
+  int  store(const char *to,uint length,CHARSET_INFO *cs)=0;
   void make_field(Send_field *);
   uint size_of() const { return sizeof(*this); }
   CHARSET_INFO *charset(void) const { return field_charset; }
@@ -905,7 +907,6 @@ public:
   bool zero_pack() const { return 0; }
   void reset(void) { charset()->cset->fill(charset(),ptr,field_length,' '); }
   int  store(const char *to,uint length,CHARSET_INFO *charset);
-  int  store(double nr);
   int  store(longlong nr);
   double val_real(void);
   longlong val_int(void);
@@ -951,7 +952,6 @@ public:
   uint32 pack_length() const { return (uint32) field_length+2; }
   uint32 key_length() const { return (uint32) field_length; }
   int  store(const char *to,uint length,CHARSET_INFO *charset);
-  int  store(double nr);
   int  store(longlong nr);
   double val_real(void);
   longlong val_int(void);
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 2812a92497..7c4b09ac3e 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -200,13 +200,13 @@ net_printf(THD *thd, uint errcode, ...)
 	    2+SQLSTATE_LENGTH+1 : 2) : 0);
 #ifndef EMBEDDED_LIBRARY
   text_pos=(char*) net->buff + head_length + offset + 1;
+  length=(char*)net->buff_end-text_pos;
+#else
+  length=sizeof(text_pos)-1;
 #endif
-  (void) my_vsnprintf(my_const_cast(char*) (text_pos),
-                      (char*)net->buff_end-text_pos,
+  length=my_vsnprintf(my_const_cast(char*) (text_pos),
+                      min(length, sizeof(net->last_error)),
                       format,args);
-  length=(uint) strlen((char*) text_pos);
-  if (length >= sizeof(net->last_error))
-    length=sizeof(net->last_error)-1;		/* purecov: inspected */
   va_end(args);
 
 #ifndef EMBEDDED_LIBRARY
diff --git a/sql/sql_string.h b/sql/sql_string.h
index 0179b3ebad..d8c4c3a87a 100644
--- a/sql/sql_string.h
+++ b/sql/sql_string.h
@@ -95,6 +95,14 @@ public:
       Ptr[str_length]=0;
     return Ptr;
   }
+  inline char *c_ptr_safe()
+  {
+    if (Ptr && str_length < Alloced_length)
+      Ptr[str_length]=0;
+    else
+      (void) realloc(str_length);
+    return Ptr;
+  }
 
   void set(String &str,uint32 offset,uint32 arg_length)
   {
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index be3ac10c39..1b091c26a6 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1936,7 +1936,7 @@ alter_list_item:
             if (check_table_name($3->table.str,$3->table.length) ||
                 $3->db.str && check_db_name($3->db.str))
             {
-              net_printf(&lex->thd->net,ER_WRONG_TABLE_NAME,$3->table.str);
+              net_printf(lex->thd,ER_WRONG_TABLE_NAME,$3->table.str);
               YYABORT;
             }
 	    lex->alter_info.flags|= ALTER_RENAME;
diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c
index 784c476272..71b5f345fd 100644
--- a/strings/my_vsnprintf.c
+++ b/strings/my_vsnprintf.c
@@ -27,7 +27,7 @@
     %#[l]d
     %#[l]u
     %#[l]x
-    %#.#s	Note #.# is skiped
+    %#.#s	Note first # is ignored
 
   RETURN
     length of result string
@@ -47,7 +47,7 @@ int my_snprintf(char* to, size_t n, const char* fmt, ...)
 int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
 {
   char *start=to, *end=to+n-1;
-  uint length, num_state, pre_zero, have_long;
+  uint length, width, pre_zero, have_long;
 
   for (; *fmt ; fmt++)
   {
@@ -62,23 +62,18 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
     /* Read max fill size (only used with %d and %u) */
     if (*fmt == '-')
       fmt++;
-    length= num_state= pre_zero= have_long= 0;
-    for (;; fmt++)
+    length= width= pre_zero= have_long= 0;
+    for (;my_isdigit(&my_charset_latin1,*fmt); fmt++)
     {
-      if (my_isdigit(&my_charset_latin1,*fmt))
-      {
-	if (!num_state)
-	{
-	  length=length*10+ (uint) (*fmt-'0');
-	  if (!length)
-	    pre_zero= 1;			/* first digit was 0 */
-	}
-	continue;
-      }
-      if (*fmt != '.' || num_state)
-	break;
-      num_state= 1;
+      length=length*10+ (uint) (*fmt-'0');
+      if (!length)
+        pre_zero= 1;			/* first digit was 0 */
     }
+    if (*fmt == '.')
+      for (fmt++;my_isdigit(&my_charset_latin1,*fmt); fmt++)
+        width=width*10+ (uint) (*fmt-'0');
+    else
+      width= ~0;
     if (*fmt == 'l')
     {
       fmt++;
@@ -90,6 +85,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
       uint plen,left_len = (uint)(end-to)+1;
       if (!par) par = (char*)"(null)";
       plen = (uint) strlen(par);
+      set_if_smaller(plen,width);
       if (left_len <= plen)
 	plen = left_len - 1;
       to=strnmov(to,par,plen);
-- 
2.30.9