Boost.Atomic: Fixed incorrect initialization of 128-bit values

This commit is contained in:
Petr Machata 2015-01-02 14:12:06 +01:00
parent 76691c3d42
commit 7a87d76794
3 changed files with 130 additions and 1 deletions

View File

@ -0,0 +1,48 @@
From 6bb71fdd8f7cc346d90fb14beb38b7297fc1ffd9 Mon Sep 17 00:00:00 2001
From: Andrey Semashev <andrey.semashev@gmail.com>
Date: Sun, 26 Jan 2014 13:58:48 +0400
Subject: [PATCH] Fixed incorrect initialization of 128-bit values, when no
native support for 128-bit integers is available.
---
include/boost/atomic/detail/cas128strong.hpp | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/include/boost/atomic/detail/cas128strong.hpp b/include/boost/atomic/detail/cas128strong.hpp
index 906c13e..dcb4d7d 100644
--- a/include/boost/atomic/detail/cas128strong.hpp
+++ b/include/boost/atomic/detail/cas128strong.hpp
@@ -196,15 +196,17 @@ protected:
public:
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
- explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
+ explicit base_atomic(value_type const& v) BOOST_NOEXCEPT
{
+ memset(&v_, 0, sizeof(v_));
memcpy(&v_, &v, sizeof(value_type));
}
void
store(value_type const& value, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
{
- storage_type value_s = 0;
+ storage_type value_s;
+ memset(&value_s, 0, sizeof(value_s));
memcpy(&value_s, &value, sizeof(value_type));
platform_fence_before_store(order);
platform_store128(value_s, &v_);
@@ -247,7 +249,9 @@ public:
memory_order success_order,
memory_order failure_order) volatile BOOST_NOEXCEPT
{
- storage_type expected_s = 0, desired_s = 0;
+ storage_type expected_s, desired_s;
+ memset(&expected_s, 0, sizeof(expected_s));
+ memset(&desired_s, 0, sizeof(desired_s));
memcpy(&expected_s, &expected, sizeof(value_type));
memcpy(&desired_s, &desired, sizeof(value_type));
--
2.1.0

View File

@ -0,0 +1,68 @@
From e4bde20f2eec0a51be14533871d2123bd2ab9cf3 Mon Sep 17 00:00:00 2001
From: Andrey Semashev <andrey.semashev@gmail.com>
Date: Fri, 28 Feb 2014 12:43:11 +0400
Subject: [PATCH] More compilation fixes for the case when 128-bit integers are
not supported.
---
include/boost/atomic/detail/gcc-atomic.hpp | 17 ++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/include/boost/atomic/detail/gcc-atomic.hpp b/include/boost/atomic/detail/gcc-atomic.hpp
index a130590..4af99a1 100644
--- a/include/boost/atomic/detail/gcc-atomic.hpp
+++ b/include/boost/atomic/detail/gcc-atomic.hpp
@@ -958,14 +958,16 @@ protected:
public:
BOOST_DEFAULTED_FUNCTION(base_atomic(void), {})
- explicit base_atomic(value_type const& v) BOOST_NOEXCEPT : v_(0)
+ explicit base_atomic(value_type const& v) BOOST_NOEXCEPT
{
+ memset(&v_, 0, sizeof(v_));
memcpy(&v_, &v, sizeof(value_type));
}
void store(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
{
- storage_type tmp = 0;
+ storage_type tmp;
+ memset(&tmp, 0, sizeof(tmp));
memcpy(&tmp, &v, sizeof(value_type));
__atomic_store_n(&v_, tmp, atomics::detail::convert_memory_order_to_gcc(order));
}
@@ -980,7 +982,8 @@ public:
value_type exchange(value_type const& v, memory_order order = memory_order_seq_cst) volatile BOOST_NOEXCEPT
{
- storage_type tmp = 0;
+ storage_type tmp;
+ memset(&tmp, 0, sizeof(tmp));
memcpy(&tmp, &v, sizeof(value_type));
tmp = __atomic_exchange_n(&v_, tmp, atomics::detail::convert_memory_order_to_gcc(order));
value_type res;
@@ -994,7 +997,9 @@ public:
memory_order success_order,
memory_order failure_order) volatile BOOST_NOEXCEPT
{
- storage_type expected_s = 0, desired_s = 0;
+ storage_type expected_s, desired_s;
+ memset(&expected_s, 0, sizeof(expected_s));
+ memset(&desired_s, 0, sizeof(desired_s));
memcpy(&expected_s, &expected, sizeof(value_type));
memcpy(&desired_s, &desired, sizeof(value_type));
const bool success = __atomic_compare_exchange_n(&v_, &expected_s, desired_s, false,
@@ -1010,7 +1015,9 @@ public:
memory_order success_order,
memory_order failure_order) volatile BOOST_NOEXCEPT
{
- storage_type expected_s = 0, desired_s = 0;
+ storage_type expected_s, desired_s;
+ memset(&expected_s, 0, sizeof(expected_s));
+ memset(&desired_s, 0, sizeof(desired_s));
memcpy(&expected_s, &expected, sizeof(value_type));
memcpy(&desired_s, &desired, sizeof(value_type));
const bool success = __atomic_compare_exchange_n(&v_, &expected_s, desired_s, true,
--
2.1.0

View File

@ -36,7 +36,7 @@ Name: boost
Summary: The free peer-reviewed portable C++ source libraries
Version: 1.55.0
%define version_enc 1_55_0
Release: 5%{?dist}
Release: 6%{?dist}
License: Boost and MIT and Python
%define toplev_dirname %{name}_%{version_enc}
@ -99,6 +99,7 @@ Patch5: boost-1.48.0-add-bjam-man-page.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=828856
# https://bugzilla.redhat.com/show_bug.cgi?id=828857
# https://svn.boost.org/trac/boost/ticket/6701
Patch15: boost-1.50.0-pool.patch
# https://svn.boost.org/trac/boost/ticket/8844
@ -160,6 +161,10 @@ Patch57: boost-1.55.0-spirit-unused_typedefs.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=1159960
Patch58: boost-1.54.0-smart_ptr-shared_ptr_at.patch
# https://bugzilla.redhat.com/show_bug.cgi?id=1177066
Patch59: boost-1.55.0-atomic-int128_1.patch
Patch60: boost-1.55.0-atomic-int128_2.patch
%bcond_with tests
%bcond_with docs_generated
@ -647,6 +652,8 @@ a number of significant features and is now developed independently
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p2
%patch60 -p2
# At least python2_version needs to be a macro so that it's visible in
# %%install as well.
@ -1249,6 +1256,12 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/bjam.1*
%changelog
* Fri Jan 2 2015 Petr Machata <pmachata@redhat.com> - 1.55.0-6
- Boost.Atomic: Fixed incorrect initialization of 128-bit values, when
no native support for 128-bit integers is available.
(boost-1.55.0-atomic-int128_1.patch,
boost-1.55.0-atomic-int128_2.patch)
* Wed Nov 12 2014 Petr Machata <pmachata@redhat.com> - 1.55.0-5
- Fix boost::shared_ptr<T>::operator[], which was ill-formed for
non-array T's. (boost-1.54.0-smart_ptr-shared_ptr_at.patch)