From dc81a88f66de8b82f70a434a734df72fd9669c88 Mon Sep 17 00:00:00 2001 From: Keichi Takahashi Date: Sun, 8 Mar 2020 17:42:39 +0900 Subject: [PATCH] Fix unaligned memory access in SSC engine --- source/adios2/engine/ssc/SscReader.tcc | 4 ++-- source/adios2/helper/adiosMpiHandshake.cpp | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/adios2/engine/ssc/SscReader.tcc b/source/adios2/engine/ssc/SscReader.tcc index 2e4dad6ded..1d3c9caf90 100644 --- a/source/adios2/engine/ssc/SscReader.tcc +++ b/source/adios2/engine/ssc/SscReader.tcc @@ -96,8 +96,8 @@ void SscReader::GetDeferredCommon(Variable &variable, T *data) b.shape.size() == 1 and b.start[0] == 0 and b.count[0] == 1 and b.shape[0] == 1) { - data[0] = reinterpret_cast(m_Buffer.data() + - b.bufferStart)[0]; + std::memcpy(data, m_Buffer.data() + b.bufferStart, + sizeof(T)); } else { diff --git a/source/adios2/helper/adiosMpiHandshake.cpp b/source/adios2/helper/adiosMpiHandshake.cpp index 4e8f5c14c2..e14c258f69 100644 --- a/source/adios2/helper/adiosMpiHandshake.cpp +++ b/source/adios2/helper/adiosMpiHandshake.cpp @@ -56,11 +56,13 @@ void MpiHandshake::Test() size_t offset = PlaceInBuffer(stream, rank); char mode = m_Buffer[offset]; offset += sizeof(char); - int appMasterRank = - reinterpret_cast(m_Buffer.data() + offset)[0]; + int appMasterRank; + std::memcpy(&appMasterRank, m_Buffer.data() + offset, + sizeof(appMasterRank)); offset += sizeof(int); - int appSize = - reinterpret_cast(m_Buffer.data() + offset)[0]; + int appSize; + std::memcpy(&appSize, m_Buffer.data() + offset, + sizeof(appSize)); offset += sizeof(int); std::string filename = m_Buffer.data() + offset; m_AppsSize[appMasterRank] = appSize;