summaryrefslogtreecommitdiff
path: root/sql/item_strfunc.cc
diff options
context:
space:
mode:
authorunknown <evgen@moonbone.local>2007-03-10 19:55:34 +0300
committerunknown <evgen@moonbone.local>2007-03-10 19:55:34 +0300
commit816ea8a379f38d4b38e46d61d23577733a222850 (patch)
tree5d2667e4ea4f63389e7affb02936eb166ab9304d /sql/item_strfunc.cc
parent1631f65dfd757282ac480fd20b3fe7b262f500c5 (diff)
downloadmariadb-git-816ea8a379f38d4b38e46d61d23577733a222850.tar.gz
Bug#15757: Wrong SUBSTRING() result when a tmp table was employed.
When the SUBSTRING() function was used over a LONGTEXT field the max_length of the SUBSTRING() result was wrongly calculated and set to 0. As the max_length parameter is used while tmp field creation it limits the length of the result field and leads to printing an empty string instead of the correct result. Now the Item_func_substr::fix_length_and_dec() function correctly calculates the max_length parameter. mysql-test/t/func_str.test: Added a test case for the bug#15757: Wrong SUBSTRING() result when a tmp table was employed. mysql-test/r/func_str.result: Added a test case for the bug#15757: Wrong SUBSTRING() result when a tmp table was employed. sql/item_strfunc.cc: Bug#15757: Wrong SUBSTRING() result when a tmp table was employed. Now the Item_func_substr::fix_length_and_dec() function correctly calculates the max_length parameter.
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r--sql/item_strfunc.cc7
1 files changed, 3 insertions, 4 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index 385f4ad9770..1d1f433789b 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -1184,11 +1184,10 @@ void Item_func_substr::fix_length_and_dec()
if (args[1]->const_item())
{
int32 start= (int32) args[1]->val_int();
- start= (int32)((start < 0) ? max_length + start : start - 1);
- if (start < 0 || start >= (int32) max_length)
- max_length=0; /* purecov: inspected */
+ if (start < 0)
+ max_length= ((uint)(-start) > max_length) ? 0 : (uint)(-start);
else
- max_length-= (uint) start;
+ max_length-= min((uint)(start - 1), max_length);
}
if (arg_count == 3 && args[2]->const_item())
{