Tor,
Thank you for fixing this by adding proper assignment and copy operators. The
patch is approved, but I want you to add a unit test that would fail prior to
the fix, e.g. like this:
TEST_F(DecimalTest, CopyAndCompare)
{
ulonglong val= 42;
EXPECT_EQ(0, ulonglong2decimal(val, &d1));
d2= d1; // operator=()
my_decimal d3(d1); // Copy constructor.
EXPECT_EQ(0, my_decimal_cmp(&d1, &d2));
EXPECT_EQ(0, my_decimal_cmp(&d2, &d3));
EXPECT_EQ(0, my_decimal_cmp(&d3, &d1));
ulonglong val1, val2, val3;
EXPECT_EQ(0, decimal2ulonglong(&d1, &val1));
EXPECT_EQ(0, decimal2ulonglong(&d2, &val2));
EXPECT_EQ(0, decimal2ulonglong(&d3, &val3));
EXPECT_EQ(val, val1);
EXPECT_EQ(val, val2);
EXPECT_EQ(val, val3);
+ val= 45;
+ EXPECT_EQ(0, ulonglong2decimal(val, &d1));
+ EXPECT_EQ(1, my_decimal_cmp(&d1, &d2));
}
On 01/13/2011 12:37 PM, Tor Didriksen wrote:
> #At file:///export/home/didrik/repo/trunk-bug59241divmod/ based on
> revid:ole.john.aske@stripped
>
> 3498 Tor Didriksen 2011-01-13
> Bug #59241 invalid memory read in do_div_mod with doubly assigned variables
>
> Fix: copy my_decimal by value, to avoid dangling pointers.
> @ mysql-test/r/func_math.result
> New test case.
> @ mysql-test/t/func_math.test
> New test case.
> @ sql/item_cmpfunc.cc
> No need to call fix_buffer_pointer() anymore.
> @ sql/item_func.cc
> Copy my_decimal by value, to avoid dangling pointers.
> @ sql/my_decimal.h
> Implement proper copy constructor and assignment operator for my_decimal.
> @ sql/sql_analyse.cc
> No need to call fix_buffer_pointer() anymore.
> @ strings/decimal.c
> Remove #line directive: it messes up TAGS and it confuses gdb when
> debugging.
> @ unittest/gunit/CMakeLists.txt
> New unit test.
> @ unittest/gunit/my_decimal-t.cc
> Unit test for my_decimal copy constructor and assignment operator.
>
> added:
> unittest/gunit/my_decimal-t.cc
> modified:
> mysql-test/r/func_math.result
> mysql-test/t/func_math.test
> sql/item_cmpfunc.cc
> sql/item_func.cc
> sql/my_decimal.h
> sql/sql_analyse.cc
> strings/decimal.c
> unittest/gunit/CMakeLists.txt
--
Jørgen Løland | Senior Software Engineer | +47 73842138
Oracle MySQL
Trondheim, Norway