diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 5dadcfea32d9e7f6c8fa182df524db6da4d80151..ab9fb43c9748735caad7af17bbdf60d3502376ed 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -1427,7 +1427,7 @@ bool Foam::ping } // Fill sockaddr_in structure with dest address and port - memset(reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr)); + std::memset(reinterpret_cast<char *>(&destAddr), '\0', sizeof(destAddr)); destAddr.sin_family = AF_INET; destAddr.sin_port = htons(ushort(destPort)); destAddr.sin_addr.s_addr = addr; diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index c87607b8244474bdace13d31eb0ca8947595d1ea..a4b35b72fb2b84f7f831c31ebf53d0ad5faaa75f 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -58,7 +58,10 @@ void Foam::List<T>::doResize(const label newSize) #ifdef USEMEMCPY if (is_contiguous<T>::value) { - memcpy(nv, this->v_, overlap*sizeof(T)); + std::memcpy + ( + static_cast<void*>(nv), this->v_, overlap*sizeof(T) + ); } else #endif @@ -184,21 +187,26 @@ Foam::List<T>::List(const UList<T>& a) : UList<T>(nullptr, a.size_) { - if (this->size_) + const label len = this->size_; + + if (len) { doAlloc(); #ifdef USEMEMCPY if (is_contiguous<T>::value) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast<void*>(this->v_), a.v_, this->byteSize() + ); } else #endif { List_ACCESS(T, (*this), vp); List_CONST_ACCESS(T, a, ap); - List_FOR_ALL((*this), i) + for (label i = 0; i < len; ++i) { vp[i] = ap[i]; } @@ -212,21 +220,26 @@ Foam::List<T>::List(const List<T>& a) : UList<T>(nullptr, a.size_) { - if (this->size_) + const label len = this->size_; + + if (len) { doAlloc(); #ifdef USEMEMCPY if (is_contiguous<T>::value) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast<void*>(this->v_), a.v_, this->byteSize() + ); } else #endif { List_ACCESS(T, (*this), vp); List_CONST_ACCESS(T, a, ap); - List_FOR_ALL((*this), i) + for (label i = 0; i < len; ++i) { vp[i] = ap[i]; } @@ -246,22 +259,29 @@ Foam::List<T>::List(List<T>& a, bool reuse) this->v_ = a.v_; a.v_ = nullptr; a.size_ = 0; + return; } - else if (this->size_) + + const label len = this->size_; + + if (len) { doAlloc(); #ifdef USEMEMCPY if (is_contiguous<T>::value) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast<void*>(this->v_), a.v_, this->byteSize() + ); } else #endif { List_ACCESS(T, (*this), vp); List_CONST_ACCESS(T, a, ap); - List_FOR_ALL((*this), i) + for (label i = 0; i < len; ++i) { vp[i] = ap[i]; } @@ -453,19 +473,24 @@ void Foam::List<T>::operator=(const UList<T>& a) { reAlloc(a.size_); - if (this->size_) + const label len = this->size_; + + if (len) { #ifdef USEMEMCPY if (is_contiguous<T>::value) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast<void*>(this->v_), a.v_, this->byteSize() + ); } else #endif { List_ACCESS(T, (*this), vp); List_CONST_ACCESS(T, a, ap); - List_FOR_ALL((*this), i) + for (label i = 0; i < len; ++i) { vp[i] = ap[i]; } @@ -521,7 +546,7 @@ void Foam::List<T>::operator=(const IndirectListBase<T, Addr>& list) { List_ACCESS(T, (*this), vp); - for (label i=0; i<len; ++i) + for (label i=0; i < len; ++i) { vp[i] = list[i]; } diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 5a4adac85c2622b09f219acab87a50f7737c4c95..415ffd7d1fe5a63126dfcb3f921e0dd214050053 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -117,7 +117,10 @@ void Foam::UList<T>::deepCopy(const UList<T>& list) #ifdef USEMEMCPY if (is_contiguous<T>::value) { - memcpy(this->v_, list.v_, this->byteSize()); + std::memcpy + ( + static_cast<void*>(this->v_), list.v_, this->byteSize() + ); } else #endif diff --git a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C index e6f11c5e6ec763b4570c4a1e06daacddfc44a7da..261d2ef4b969922d62e868b64c524c7de2b888ba 100644 --- a/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C +++ b/src/OpenFOAM/matrices/lduMatrix/lduAddressing/lduInterface/processorLduInterfaceTemplates.C @@ -50,7 +50,7 @@ void Foam::processorLduInterface::send ( commsType, neighbProcNo(), - reinterpret_cast<const char*>(f.begin()), + reinterpret_cast<const char*>(f.cdata()), nBytes, tag(), comm() @@ -64,20 +64,23 @@ void Foam::processorLduInterface::send ( commsType, neighbProcNo(), - receiveBuf_.begin(), + receiveBuf_.data(), nBytes, tag(), comm() ); resizeBuf(sendBuf_, nBytes); - memcpy(sendBuf_.begin(), f.begin(), nBytes); + std::memcpy + ( + static_cast<void*>(sendBuf_.data()), f.cdata(), nBytes + ); OPstream::write ( commsType, neighbProcNo(), - sendBuf_.begin(), + sendBuf_.cdata(), nBytes, tag(), comm() @@ -109,7 +112,7 @@ void Foam::processorLduInterface::receive ( commsType, neighbProcNo(), - reinterpret_cast<char*>(f.begin()), + reinterpret_cast<char*>(f.data()), f.byteSize(), tag(), comm() @@ -117,7 +120,10 @@ void Foam::processorLduInterface::receive } else if (commsType == Pstream::commsTypes::nonBlocking) { - memcpy(f.begin(), receiveBuf_.begin(), f.byteSize()); + std::memcpy + ( + static_cast<void*>(f.data()), receiveBuf_.cdata(), f.byteSize() + ); } else { @@ -156,10 +162,10 @@ void Foam::processorLduInterface::compressedSend label nFloats = nm1 + nlast; label nBytes = nFloats*sizeof(float); - const scalar *sArray = reinterpret_cast<const scalar*>(f.begin()); + const scalar *sArray = reinterpret_cast<const scalar*>(f.cdata()); const scalar *slast = &sArray[nm1]; resizeBuf(sendBuf_, nBytes); - float *fArray = reinterpret_cast<float*>(sendBuf_.begin()); + float *fArray = reinterpret_cast<float*>(sendBuf_.data()); for (label i=0; i<nm1; i++) { @@ -178,7 +184,7 @@ void Foam::processorLduInterface::compressedSend ( commsType, neighbProcNo(), - sendBuf_.begin(), + sendBuf_.cdata(), nBytes, tag(), comm() @@ -192,7 +198,7 @@ void Foam::processorLduInterface::compressedSend ( commsType, neighbProcNo(), - receiveBuf_.begin(), + receiveBuf_.data(), nBytes, tag(), comm() @@ -202,7 +208,7 @@ void Foam::processorLduInterface::compressedSend ( commsType, neighbProcNo(), - sendBuf_.begin(), + sendBuf_.cdata(), nBytes, tag(), comm() @@ -249,7 +255,7 @@ void Foam::processorLduInterface::compressedReceive ( commsType, neighbProcNo(), - receiveBuf_.begin(), + receiveBuf_.data(), nBytes, tag(), comm() @@ -263,9 +269,9 @@ void Foam::processorLduInterface::compressedReceive } const float *fArray = - reinterpret_cast<const float*>(receiveBuf_.begin()); + reinterpret_cast<const float*>(receiveBuf_.cdata()); f.last() = reinterpret_cast<const Type&>(fArray[nm1]); - scalar *sArray = reinterpret_cast<scalar*>(f.begin()); + scalar *sArray = reinterpret_cast<scalar*>(f.data()); const scalar *slast = &sArray[nm1]; for (label i=0; i<nm1; i++) diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C index 889b9140a4ae77cee3b1aa2dbcabf3b805a1c293..7c4179322deaa3ae895de14fe197f08cdc87cd97 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C @@ -67,7 +67,7 @@ static inline uint32_t swapBytes(uint32_t n) // *(uint32_t *) cp = val static inline void set_uint32(unsigned char *dst, uint32_t v) { - memcpy(dst, &v, sizeof(uint32_t)); + std::memcpy(dst, &v, sizeof(uint32_t)); } //! \endcond @@ -95,7 +95,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len) unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_); - memcpy(&bufp[remaining], data, add); + std::memcpy(&bufp[remaining], data, add); bufLen_ += add; if (bufLen_ > 64) @@ -105,7 +105,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len) bufLen_ &= 63; // The regions in the following copy operation do not // (cannot) overlap - memcpy(buffer_, &bufp[(remaining + add) & ~63], bufLen_); + std::memcpy(buffer_, &bufp[(remaining + add) & ~63], bufLen_); } data = reinterpret_cast<const unsigned char*>(data) + add; @@ -115,7 +115,7 @@ void Foam::SHA1::processBytes(const void *data, size_t len) // Process available complete blocks while (len >= 64) { - processBlock(memcpy(buffer_, data, 64), 64); + processBlock(std::memcpy(buffer_, data, 64), 64); data = reinterpret_cast<const unsigned char*>(data) + 64; len -= 64; } @@ -126,13 +126,13 @@ void Foam::SHA1::processBytes(const void *data, size_t len) unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_); size_t remaining = bufLen_; - memcpy(&bufp[remaining], data, len); + std::memcpy(&bufp[remaining], data, len); remaining += len; if (remaining >= 64) { processBlock(buffer_, 64); remaining -= 64; - memcpy(buffer_, &buffer_[16], remaining); + std::memcpy(buffer_, &buffer_[16], remaining); } bufLen_ = remaining; } @@ -355,7 +355,7 @@ bool Foam::SHA1::finalize() unsigned char* bufp = reinterpret_cast<unsigned char *>(buffer_); - memcpy(&bufp[bytes], fillbuf, (size-2) * sizeof(uint32_t) - bytes); + std::memcpy(&bufp[bytes], fillbuf, (size-2) * sizeof(uint32_t) - bytes); // Process remaining bytes processBlock(buffer_, size * sizeof(uint32_t)); diff --git a/src/Pstream/mpi/UPstream.C b/src/Pstream/mpi/UPstream.C index d291608731a549934bc83df513fc9d7440246c87..142d520344c7ffa05a3c90f59ab679432e112467 100644 --- a/src/Pstream/mpi/UPstream.C +++ b/src/Pstream/mpi/UPstream.C @@ -573,7 +573,7 @@ void Foam::UPstream::allToAll << " does not equal bytes to receive " << recvSizes[0] << Foam::abort(FatalError); } - memmove(recvData, &sendData[sendOffsets[0]], recvSizes[0]); + std::memmove(recvData, &sendData[sendOffsets[0]], recvSizes[0]); } else { @@ -639,7 +639,7 @@ void Foam::UPstream::gather if (!UPstream::parRun()) { - memmove(recvData, sendData, sendSize); + std::memmove(recvData, sendData, sendSize); } else { @@ -702,7 +702,7 @@ void Foam::UPstream::scatter if (!UPstream::parRun()) { - memmove(recvData, sendData, recvSize); + std::memmove(recvData, sendData, recvSize); } else {