diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 8b20ae68dce..afd8c3430b3 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -1776,6 +1776,14 @@ end loop; end| call bug5287(1)| drop procedure bug5287| +create procedure bug5307() +begin +end; set @x = 3| +call bug5307()| +select @x| +@x +3 +drop procedure bug5307| drop table if exists fac| create table fac (n int unsigned not null primary key, f bigint unsigned)| create procedure ifac(n int unsigned) diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index c420865b2b3..92d6110cf7a 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -1942,6 +1942,18 @@ call bug5287(1)| drop procedure bug5287| +# +# BUG#5307: Stored procedure allows statement after BEGIN ... END +# +create procedure bug5307() +begin +end; set @x = 3| + +call bug5307()| +select @x| +drop procedure bug5307| + + # # Some "real" examples # diff --git a/sql/sp_head.cc b/sql/sp_head.cc index b2d3b8202c8..16d13154263 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -288,6 +288,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 */ /* During parsing, we must use thd->mem_root */ MEM_ROOT *root= &thd->mem_root; @@ -351,9 +352,17 @@ sp_head::init_strings(THD *thd, LEX *lex, sp_name *name) (char *)m_returns_begin, m_retstr.length); } } - m_body.length= lex->end_of_query - m_body_begin; + 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; + } m_body.str= strmake_root(root, (char *)m_body_begin, m_body.length); - m_defstr.length= lex->end_of_query - lex->buf; + m_defstr.length= lex->ptr - lex->buf; + m_defstr.length-= n; m_defstr.str= strmake_root(root, (char *)lex->buf, m_defstr.length); DBUG_VOID_RETURN; }