diff --git a/include/sql_string.h b/include/sql_string.h index 8da554bef1ad..8c7052138829 100644 --- a/include/sql_string.h +++ b/include/sql_string.h @@ -679,7 +679,8 @@ class String char *ret= static_cast(alloc_root(root, m_length + 1)); if (ret != NULL) { - memcpy(ret, m_ptr, m_length); + if (m_length > 0) + memcpy(ret, m_ptr, m_length); ret[m_length]= 0; } return ret; diff --git a/plugin/keyring/common/keyring_key.cc b/plugin/keyring/common/keyring_key.cc index 96695dd02eaf..bbb64f593558 100644 --- a/plugin/keyring/common/keyring_key.cc +++ b/plugin/keyring/common/keyring_key.cc @@ -79,7 +79,8 @@ void Key::store_field_length(uchar *buffer, size_t *buffer_position, size_t leng void Key::store_field(uchar *buffer, size_t *buffer_position, const char *field, size_t field_length) const { - memcpy(buffer + *buffer_position, field, field_length); + if (field_length > 0) + memcpy(buffer + *buffer_position, field, field_length); *buffer_position+= field_length; } diff --git a/unittest/gunit/gis_algos-t.cc b/unittest/gunit/gis_algos-t.cc index 9c9e6a5fd1a9..8d53c59a8d83 100644 --- a/unittest/gunit/gis_algos-t.cc +++ b/unittest/gunit/gis_algos-t.cc @@ -66,7 +66,7 @@ void SetRingOrderTest::set_order_and_compare(const std::string &s1, wkt.set(s1.c_str(), s1.length(), latincc); wkt2.set(s2.c_str(), s2.length(), latincc); - Gis_polygon_ring *ringp= static_cast + Gis_line_string *ringp= static_cast (geometry_from_text(wkt, &str, &buffer)); DBUG_ASSERT(ringp->get_geotype() == Geometry::wkb_linestring); Gis_polygon_ring ring(ringp->get_ptr(), @@ -74,7 +74,7 @@ void SetRingOrderTest::set_order_and_compare(const std::string &s1, EXPECT_EQ(ring.set_ring_order(want_ccw), false); - ringp= static_cast(geometry_from_text(wkt2, &str2, + ringp= static_cast(geometry_from_text(wkt2, &str2, &buffer2)); DBUG_ASSERT(ringp->get_geotype() == Geometry::wkb_linestring); Gis_polygon_ring ring2(ringp->get_ptr(), @@ -155,7 +155,7 @@ TEST_F(SetRingOrderTest, RingDegradedToPointTest) std::string s1("linestring(0 0, 0 0, 0 0, 0 0, 0 0)"); wkt.set(s1.c_str(), s1.length(), latincc); - Gis_polygon_ring *ringp= static_cast + Gis_line_string *ringp= static_cast (geometry_from_text(wkt, &str, &buffer)); DBUG_ASSERT(ringp->get_geotype() == Geometry::wkb_linestring); Gis_polygon_ring ring(ringp->get_ptr(),