MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Jim Winstead Date:June 1 2005 4:48pm
Subject:bk commit into 4.1 tree (jimw:1.2303) BUG#10944
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of jimw. When jimw 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.2303 05/06/01 09:48:25 jimw@stripped +3 -0
  Fix handling of NULL fields in FIELD(). (Bug #10944)

  sql/item_func.cc
    1.247 05/06/01 09:48:22 jimw@stripped +4 -0
    Handle NULL as first argument to FIELD()

  mysql-test/t/func_str.test
    1.72 05/06/01 09:48:22 jimw@stripped +6 -0
    Add regression tests

  mysql-test/r/func_str.result
    1.91 05/06/01 09:48:22 jimw@stripped +6 -0
    Update results

  sql/item_func.cc
    1.246 05/06/01 09:20:32 jimw@stripped +4 -4
    Fix handling of NULL arguments to FIELD()

# 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:	jimw
# Host:	rama.(none)
# Root:	/home/jimw/my/mysql-4.1-10944

--- 1.245/sql/item_func.cc	2005-05-26 03:09:09 -07:00
+++ 1.247/sql/item_func.cc	2005-06-01 09:48:22 -07:00
@@ -1488,6 +1488,10 @@
 longlong Item_func_field::val_int()
 {
   DBUG_ASSERT(fixed == 1);
+
+  if (args[0]->null_value)
+    return 0;
+
   if (cmp_type == STRING_RESULT)
   {
     String *field;
@@ -1505,8 +1509,8 @@
     longlong val= args[0]->val_int();
     for (uint i=1; i < arg_count ; i++)
     {
-      if (val == args[i]->val_int())
- 	return (longlong) (i);
+      if (!args[i]->null_value && val == args[i]->val_int())
+        return (longlong) (i);
     }
   }
   else
@@ -1514,8 +1518,8 @@
     double val= args[0]->val();
     for (uint i=1; i < arg_count ; i++)
     {
-      if (val == args[i]->val())
- 	return (longlong) (i);
+      if (!args[i]->null_value && val == args[i]->val())
+        return (longlong) (i);
     }
   }
   return 0;

--- 1.90/mysql-test/r/func_str.result	2005-03-24 06:08:03 -08:00
+++ 1.91/mysql-test/r/func_str.result	2005-06-01 09:48:22 -07:00
@@ -783,3 +783,9 @@
 1	foo
 2	NULL
 DROP TABLE t1, t2;
+select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
+field(0,NULL,1,0)	field("",NULL,"bar","")	field(0.0,NULL,1.0,0.0)
+3	3	3
+select field(NULL,1,2,NULL), field(NULL,1,2,0);
+field(NULL,1,2,NULL)	field(NULL,1,2,0)
+0	0

--- 1.71/mysql-test/t/func_str.test	2005-03-24 06:08:03 -08:00
+++ 1.72/mysql-test/t/func_str.test	2005-06-01 09:48:22 -07:00
@@ -521,3 +521,9 @@
 
 DROP TABLE t1, t2;
 
+
+#
+# Bug #10944: Mishandling of NULL arguments in FIELD()
+#
+select field(0,NULL,1,0), field("",NULL,"bar",""), field(0.0,NULL,1.0,0.0);
+select field(NULL,1,2,NULL), field(NULL,1,2,0);
Thread
bk commit into 4.1 tree (jimw:1.2303) BUG#10944Jim Winstead1 Jun