diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index ec024922ef..191694981d 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -1428,7 +1428,7 @@ bool Foam::ping } // Fill sockaddr_in structure with dest address and port - memset(reinterpret_cast(&destAddr), '\0', sizeof(destAddr)); + std::memset(reinterpret_cast(&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 af83584d7f..8953aa436d 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -59,7 +59,10 @@ void Foam::List::doResize(const label newSize) #ifdef USEMEMCPY if (contiguous()) { - memcpy(nv, this->v_, overlap*sizeof(T)); + std::memcpy + ( + static_cast(nv), this->v_, overlap*sizeof(T) + ); } else #endif @@ -185,21 +188,26 @@ Foam::List::List(const UList& a) : UList(nullptr, a.size_) { - if (this->size_) + const label len = this->size_; + + if (len) { doAlloc(); #ifdef USEMEMCPY if (contiguous()) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast(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]; } @@ -213,21 +221,26 @@ Foam::List::List(const List& a) : UList(nullptr, a.size_) { - if (this->size_) + const label len = this->size_; + + if (len) { doAlloc(); #ifdef USEMEMCPY if (contiguous()) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast(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]; } @@ -247,22 +260,29 @@ Foam::List::List(List& 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 (contiguous()) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast(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]; } @@ -454,19 +474,24 @@ void Foam::List::operator=(const UList& a) { reAlloc(a.size_); - if (this->size_) + const label len = this->size_; + + if (len) { #ifdef USEMEMCPY if (contiguous()) { - memcpy(this->v_, a.v_, this->byteSize()); + std::memcpy + ( + static_cast(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]; } @@ -522,7 +547,7 @@ void Foam::List::operator=(const IndirectListBase& list) { List_ACCESS(T, (*this), vp); - for (label i=0; i::deepCopy(const UList& list) #ifdef USEMEMCPY if (contiguous()) { - memcpy(this->v_, list.v_, this->byteSize()); + std::memcpy + ( + static_cast(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 f3dd2f741e..f428e0b43c 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(f.begin()), + reinterpret_cast(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(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(f.begin()), + reinterpret_cast(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(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(f.begin()); + const scalar *sArray = reinterpret_cast(f.cdata()); const scalar *slast = &sArray[nm1]; resizeBuf(sendBuf_, nBytes); - float *fArray = reinterpret_cast(sendBuf_.begin()); + float *fArray = reinterpret_cast(sendBuf_.data()); for (label i=0; i(receiveBuf_.begin()); + reinterpret_cast(receiveBuf_.cdata()); f.last() = reinterpret_cast(fArray[nm1]); - scalar *sArray = reinterpret_cast(f.begin()); + scalar *sArray = reinterpret_cast(f.data()); const scalar *slast = &sArray[nm1]; for (label i=0; i(buffer_); - memcpy(&bufp[remaining], data, add); + std::memcpy(&bufp[remaining], data, add); bufLen_ += add; if (bufLen_ > 64) @@ -106,7 +106,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(data) + add; @@ -116,7 +116,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(data) + 64; len -= 64; } @@ -127,13 +127,13 @@ void Foam::SHA1::processBytes(const void *data, size_t len) unsigned char* bufp = reinterpret_cast(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; } @@ -356,7 +356,7 @@ bool Foam::SHA1::finalize() unsigned char* bufp = reinterpret_cast(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 84069910da..98fedcd537 100644 --- a/src/Pstream/mpi/UPstream.C +++ b/src/Pstream/mpi/UPstream.C @@ -574,7 +574,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 { @@ -640,7 +640,7 @@ void Foam::UPstream::gather if (!UPstream::parRun()) { - memmove(recvData, sendData, sendSize); + std::memmove(recvData, sendData, sendSize); } else { @@ -703,7 +703,7 @@ void Foam::UPstream::scatter if (!UPstream::parRun()) { - memmove(recvData, sendData, recvSize); + std::memmove(recvData, sendData, recvSize); } else {