summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <pem@mysql.com>2005-11-15 13:27:00 +0100
committerunknown <pem@mysql.com>2005-11-15 13:27:00 +0100
commitd9c7aaf23ff30675682775864c269bde84a3bc03 (patch)
tree07bc988af7a3931dc70254adb65d88d987c38202
parent7f3146bb5c98e4b324858765df26ed32f27cbd9b (diff)
parent4760021e147db0c30f20ac6f881ce024028e1fa9 (diff)
downloadmariadb-git-d9c7aaf23ff30675682775864c269bde84a3bc03.tar.gz
Merge mysql.com:/usr/local/bk/mysql-5.0
into mysql.com:/usr/home/pem/bug14723/mysql-5.0
-rw-r--r--mysql-test/r/sp.result31
-rw-r--r--mysql-test/t/sp.test32
-rw-r--r--sql/sp_head.cc25
3 files changed, 77 insertions, 11 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result
index d50e6dd3751..1e49f966bc4 100644
--- a/mysql-test/r/sp.result
+++ b/mysql-test/r/sp.result
@@ -3617,4 +3617,35 @@ count(*)
drop table t3, t4|
drop procedure bug14210|
set @@session.max_heap_table_size=default|
+drop function if exists bug14723|
+drop procedure if exists bug14723|
+/*!50003 create function bug14723()
+returns bigint(20)
+main_loop: begin
+return 42;
+end */;;
+show create function bug14723;;
+Function sql_mode Create Function
+bug14723 CREATE FUNCTION `bug14723`() RETURNS bigint(20)
+main_loop: begin
+return 42;
+end
+select bug14723();;
+bug14723()
+42
+/*!50003 create procedure bug14723()
+main_loop: begin
+select 42;
+end */;;
+show create procedure bug14723;;
+Procedure sql_mode Create Procedure
+bug14723 CREATE PROCEDURE `bug14723`()
+main_loop: begin
+select 42;
+end
+call bug14723();;
+42
+42
+drop function bug14723|
+drop procedure bug14723|
drop table t1,t2;
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test
index eaf69c0ab03..362faec167c 100644
--- a/mysql-test/t/sp.test
+++ b/mysql-test/t/sp.test
@@ -4541,6 +4541,38 @@ drop table t3, t4|
drop procedure bug14210|
set @@session.max_heap_table_size=default|
+
+#
+# BUG#1473: Dumping of stored functions seems to cause corruption in
+# the function body
+#
+--disable_warnings
+drop function if exists bug14723|
+drop procedure if exists bug14723|
+--enable_warnings
+
+delimiter ;;|
+/*!50003 create function bug14723()
+ returns bigint(20)
+main_loop: begin
+ return 42;
+end */;;
+show create function bug14723;;
+select bug14723();;
+
+/*!50003 create procedure bug14723()
+main_loop: begin
+ select 42;
+end */;;
+show create procedure bug14723;;
+call bug14723();;
+
+delimiter |;;
+
+drop function bug14723|
+drop procedure bug14723|
+
+
#
# BUG#NNNN: New bug synopsis
#
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 08a189165b5..facd984cc50 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -476,7 +476,7 @@ void
sp_head::init_strings(THD *thd, LEX *lex, sp_name *name)
{
DBUG_ENTER("sp_head::init_strings");
- uint n; /* Counter for nul trimming */
+ uchar *endp; /* Used to trim the end */
/* During parsing, we must use thd->mem_root */
MEM_ROOT *root= thd->mem_root;
@@ -509,17 +509,20 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name)
(char *)m_param_begin, m_params.length);
}
- m_body.length= lex->ptr - m_body_begin;
- /* Trim nuls at the end */
- n= 0;
- while (m_body.length && m_body_begin[m_body.length-1] == '\0')
- {
- m_body.length-= 1;
- n+= 1;
- }
+ /* If ptr has overrun end_of_query then end_of_query is the end */
+ endp= (lex->ptr > lex->end_of_query ? lex->end_of_query : lex->ptr);
+ /*
+ Trim "garbage" at the end. This is sometimes needed with the
+ "/ * ! VERSION... * /" wrapper in dump files.
+ */
+ while (m_body_begin < endp &&
+ (endp[-1] <= ' ' || endp[-1] == '*' ||
+ endp[-1] == '/' || endp[-1] == ';'))
+ endp-= 1;
+
+ m_body.length= endp - m_body_begin;
m_body.str= strmake_root(root, (char *)m_body_begin, m_body.length);
- m_defstr.length= lex->ptr - lex->buf;
- m_defstr.length-= n;
+ m_defstr.length= endp - lex->buf;
m_defstr.str= strmake_root(root, (char *)lex->buf, m_defstr.length);
DBUG_VOID_RETURN;
}