MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:igor Date:July 5 2006 5:32am
Subject:bk commit into 4.1 tree (igor:1.2521) BUG#18243
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of igor. When igor does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2521 06/07/04 22:32:41 igor@stripped +4 -0
  Fixed bug #18243.
  The implementation of the method Item_func_reverse::val_str
  for the REVERSE function modified the argument of the function.
  This led to wrong results for expressions that contained
  REVERSE(ref) if ref occurred somewhere else in the expressions.
  

  sql/item_strfunc.h
    1.102 06/07/04 22:32:38 igor@stripped +1 -0
    Fixed bug #18243.
    Added tmp_value to the Item_func_reverse class to store
    the result of the function. It erroneously replaced the 
    argument before this fix.

  sql/item_strfunc.cc
    1.246 06/07/04 22:32:38 igor@stripped +16 -17
    Fixed bug #18243.
    The implementation of the method Item_func_reverse::val_str
    for the REVERSE function modified the argument of the function.
    This led to wrong results for expressions that contained
    REVERSE(ref) if ref occurred somewhere else in the expressions.
    
    The implementation of Item_func_reverse::val_str has been changed
    to make the argument intact.

  mysql-test/t/func_str.test
    1.84 06/07/04 22:32:38 igor@stripped +17 -0
    Added a test case for bug #18243.

  mysql-test/r/func_str.result
    1.102 06/07/04 22:32:38 igor@stripped +15 -0
    Added a test case for bug #18243.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	igor
# Host:	olga.mysql.com
# Root:	/home/igor/mysql-4.1-opt

--- 1.245/sql/item_strfunc.cc	2006-06-20 00:08:58 -07:00
+++ 1.246/sql/item_strfunc.cc	2006-07-04 22:32:38 -07:00
@@ -709,44 +709,43 @@ String *Item_func_reverse::val_str(Strin
 {
   DBUG_ASSERT(fixed == 1);
   String *res = args[0]->val_str(str);
-  char *ptr,*end;
+  char *ptr,*end, *tmp;
 
   if ((null_value=args[0]->null_value))
     return 0;
   /* An empty string is a special case as the string pointer may be null */
   if (!res->length())
     return &my_empty_string;
-  res=copy_if_not_alloced(str,res,res->length());
-  ptr = (char *) res->ptr();
-  end=ptr+res->length();
+  if (tmp_value.alloced_length() < res->length() &&
+      tmp_value.realloc(res->length()))
+  {
+    null_value=1;
+    return 0;
+  }
+  tmp_value.length(res->length());
+  tmp_value.set_charset(res->charset());
+  ptr= (char *) res->ptr();
+  end= ptr+res->length();
+  tmp= (char *) tmp_value.ptr() + tmp_value.length();
 #ifdef USE_MB
   if (use_mb(res->charset()))
   {
-    String tmpstr;
-    tmpstr.copy(*res);
-    char *tmp = (char *) tmpstr.ptr() + tmpstr.length();
     register uint32 l;
     while (ptr < end)
     {
-      if ((l=my_ismbchar(res->charset(), ptr,end)))
-        tmp-=l, memcpy(tmp,ptr,l), ptr+=l;
+      if ((l= my_ismbchar(res->charset(),ptr,end)))
+        tmp-= l, memcpy(tmp,ptr,l), ptr+= l;
       else
         *--tmp=*ptr++;
     }
-    memcpy((char *) res->ptr(),(char *) tmpstr.ptr(), res->length());
   }
   else
 #endif /* USE_MB */
   {
-    char tmp;
     while (ptr < end)
-    {
-      tmp=*ptr;
-      *ptr++=*--end;
-      *end=tmp;
-    }
+      *--tmp=*ptr++;
   }
-  return res;
+  return &tmp_value;
 }
 
 

--- 1.101/sql/item_strfunc.h	2006-06-20 00:08:58 -07:00
+++ 1.102/sql/item_strfunc.h	2006-07-04 22:32:38 -07:00
@@ -100,6 +100,7 @@ public:
 
 class Item_func_reverse :public Item_str_func
 {
+  String tmp_value;
 public:
   Item_func_reverse(Item *a) :Item_str_func(a) {}
   String *val_str(String *);

--- 1.101/mysql-test/r/func_str.result	2006-06-20 00:08:57 -07:00
+++ 1.102/mysql-test/r/func_str.result	2006-07-04 22:32:38 -07:00
@@ -1021,4 +1021,19 @@ select * from t1 where f1='test' and (f2
 f1	f2
 test	a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
 drop table t1;
+CREATE TABLE t1 (a varchar(10));
+INSERT INTO t1 VALUES ('abc'), ('xyz');
+SELECT a, CONCAT(a,' ',a) AS c FROM t1
+HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
+a	c
+abc	abc abc
+xyz	xyz xyz
+SELECT a, CONCAT(a,' ',a) AS c FROM t1
+HAVING LEFT(CONCAT(a,' ',a),
+LENGTH(CONCAT(a,' ',a))-
+INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
+a	c
+abc	abc abc
+xyz	xyz xyz
+DROP TABLE t1;
 End of 4.1 tests

--- 1.83/mysql-test/t/func_str.test	2006-06-20 00:08:58 -07:00
+++ 1.84/mysql-test/t/func_str.test	2006-07-04 22:32:38 -07:00
@@ -681,4 +681,21 @@ select * from t1 where f1='test' and (f2
 select * from t1 where f1='test' and (f2= sha("TEST") or f2= sha("test"));
 drop table t1;
 
+#
+# Bug#18243: REVERSE changes its argument
+#
+
+CREATE TABLE t1 (a varchar(10));
+INSERT INTO t1 VALUES ('abc'), ('xyz');
+
+SELECT a, CONCAT(a,' ',a) AS c FROM t1
+  HAVING LEFT(c,LENGTH(c)-INSTR(REVERSE(c)," ")) = a;
+
+SELECT a, CONCAT(a,' ',a) AS c FROM t1
+  HAVING LEFT(CONCAT(a,' ',a),
+              LENGTH(CONCAT(a,' ',a))-
+                     INSTR(REVERSE(CONCAT(a,' ',a))," ")) = a;
+
+DROP TABLE t1;
+ 
 --echo End of 4.1 tests
Thread
bk commit into 4.1 tree (igor:1.2521) BUG#18243igor5 Jul