diff options
author | unknown <pem@mysql.com> | 2005-10-19 14:54:54 +0200 |
---|---|---|
committer | unknown <pem@mysql.com> | 2005-10-19 14:54:54 +0200 |
commit | a7f4882a43d8db061c2241438635fb13fc1c0d37 (patch) | |
tree | eee9b75406cb564b8e00f309c9c00257e8fab4bb /mysql-test/t/sp.test | |
parent | c30d1cfd9007e5e43c916fa1fd660b706e8d9c20 (diff) | |
download | mariadb-git-a7f4882a43d8db061c2241438635fb13fc1c0d37.tar.gz |
Fixed BUG#13941: replace() string fuction behaves badly inside stored
procedure
For some functions returning strings (like "replace" and "ifnull" - where
val_str() is returning a pointer into one of the parameters) - we ended
up with a dangling pointer after the new operator destroyed the reuse item
in the eval function.
A working, if not very elegant, solution is to simply copy the string in
such cases.
mysql-test/r/sp.result:
New test case for BUG#13941.
mysql-test/t/sp.test:
New test case for BUG#13941.
sql/sp_head.cc:
Copy the string when evaluating some string functions (e.g. "replace" and "ifnull")
to avoid using a dangling pointer.
Diffstat (limited to 'mysql-test/t/sp.test')
-rw-r--r-- | mysql-test/t/sp.test | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 4b9987c2803..18607c7f13c 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -4391,6 +4391,49 @@ drop function bug7049_2| # +# BUG#13941: replace() string fuction behaves badly inside stored procedure +# (BUG#13914: IFNULL is returning garbage in stored procedure) +# +--disable_warnings +drop function if exists bug13941| +drop procedure if exists bug13941| +--enable_warnings + +create function bug13941(p_input_str text) + returns text +begin + declare p_output_str text; + + set p_output_str = p_input_str; + + set p_output_str = replace(p_output_str, 'xyzzy', 'plugh'); + set p_output_str = replace(p_output_str, 'test', 'prova'); + set p_output_str = replace(p_output_str, 'this', 'questo'); + set p_output_str = replace(p_output_str, ' a ', 'una '); + set p_output_str = replace(p_output_str, 'is', ''); + + return p_output_str; +end| + +create procedure bug13941(out sout varchar(128)) +begin + set sout = 'Local'; + set sout = ifnull(sout, 'DEF'); +end| + +# Note: The bug showed different behaviour in different types of builds, +# giving garbage results in some, and seemingly working in others. +# Running with valgrind (or purify) is the safe way to check that it's +# really working correctly. +select bug13941('this is a test')| +call bug13941(@a)| +select @a| + +drop function bug13941| +drop procedure bug13941| + + +# # BUG#NNNN: New bug synopsis # #--disable_warnings |