summaryrefslogtreecommitdiff
path: root/sql/item_strfunc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/item_strfunc.cc')
-rw-r--r--sql/item_strfunc.cc22
1 files changed, 14 insertions, 8 deletions
diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc
index d3493e1fad1..fac73a1a759 100644
--- a/sql/item_strfunc.cc
+++ b/sql/item_strfunc.cc
@@ -39,7 +39,8 @@ C_MODE_END
String my_empty_string("",default_charset_info);
-static void my_coll_agg_error(DTCollation &c1, DTCollation &c2, const char *fname)
+static void my_coll_agg_error(DTCollation &c1, DTCollation &c2,
+ const char *fname)
{
my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
c1.collation->name,c1.derivation_name(),
@@ -62,8 +63,9 @@ double Item_str_func::val()
{
DBUG_ASSERT(fixed == 1);
int err;
- String *res;
- res=val_str(&str_value);
+ char buff[64];
+ String *res, tmp(buff,sizeof(buff), &my_charset_bin);
+ res= val_str(&tmp);
return res ? my_strntod(res->charset(), (char*) res->ptr(),res->length(),
NULL, &err) : 0.0;
}
@@ -72,8 +74,9 @@ longlong Item_str_func::val_int()
{
DBUG_ASSERT(fixed == 1);
int err;
- String *res;
- res=val_str(&str_value);
+ char buff[22];
+ String *res, tmp(buff,sizeof(buff), &my_charset_bin);
+ res= val_str(&tmp);
return (res ?
my_strntoll(res->charset(), res->ptr(), res->length(), 10, NULL,
&err) :
@@ -977,14 +980,16 @@ String *Item_func_left::val_str(String *str)
DBUG_ASSERT(fixed == 1);
String *res =args[0]->val_str(str);
long length =(long) args[1]->val_int();
+ uint char_pos;
if ((null_value=args[0]->null_value))
return 0;
if (length <= 0)
return &my_empty_string;
- if (res->length() <= (uint) length)
+ if (res->length() <= (uint) length ||
+ res->length() <= (char_pos= res->charpos(length)))
return res;
- str_value.set(*res, 0, res->charpos(length));
+ str_value.set(*res, 0, char_pos);
return &str_value;
}
@@ -2195,7 +2200,8 @@ String *Item_func_conv_charset::val_str(String *str)
null_value=1;
return 0;
}
- null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(),conv_charset);
+ null_value= str_value.copy(arg->ptr(),arg->length(),arg->charset(),
+ conv_charset);
return null_value ? 0 : &str_value;
}