Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/10721 )
Change subject: Vector: Copy arrays in a sane way for non-trivially copyable types ...................................................................... Vector: Copy arrays in a sane way for non-trivially copyable types Avoids this type of compilation warnings: ‘void* memcpy(void*, const void*, size_t)’ writing to an object of non-trivially copyable type ‘class Complex<float>’; use copy-assignment or copy-initialization instead [-Werror=class-memaccess] Change-Id: I9724454dfb7b87f74f39074e4004580ac3b5fe5c --- M CommonLibs/Vector.h M Transceiver52M/signalVector.cpp 2 files changed, 23 insertions(+), 6 deletions(-) Approvals: Jenkins Builder: Verified Harald Welte: Looks good to me, approved diff --git a/CommonLibs/Vector.h b/CommonLibs/Vector.h index 51a9fb1..9119683 100644 --- a/CommonLibs/Vector.h +++ b/CommonLibs/Vector.h @@ -204,10 +204,15 @@ */ void copyToSegment(Vector<T>& other, size_t start, size_t span) const { - T* base = other.mStart + start; - assert(base+span<=other.mEnd); + unsigned int i; + T* dst = other.mStart + start; + T* src = mStart; + assert(dst+span<=other.mEnd); assert(mStart+span<=mEnd); - memcpy(base,mStart,span*sizeof(T)); + for (i = 0; i < span; i++, src++, dst++) + *dst = *src; + /*TODO if not non-trivially copyable type class, optimize: + memcpy(dst,mStart,span*sizeof(T)); */ } /** Copy all of this Vector to a segment of another Vector. */ diff --git a/Transceiver52M/signalVector.cpp b/Transceiver52M/signalVector.cpp index 55dad92..fc8157e 100644 --- a/Transceiver52M/signalVector.cpp +++ b/Transceiver52M/signalVector.cpp @@ -41,7 +41,14 @@ void signalVector::operator=(const signalVector& vector) { resize(vector.size() + vector.getStart()); - memcpy(mData, vector.mData, bytes()); + + unsigned int i; + complex *dst = mData; + complex *src = vector.mData; + for (i = 0; i < size(); i++, src++, dst++) + *dst = *src; + /* TODO: optimize for non non-trivially copyable types: */ + /*memcpy(mData, vector.mData, bytes()); */ mStart = mData + vector.getStart(); } @@ -58,8 +65,13 @@ size_t signalVector::updateHistory() { size_t num = getStart(); - - memmove(mData, mStart + this->size() - num, num * sizeof(complex)); + unsigned int i; + complex *dst = mData; + complex *src = mStart + this->size() - num; + for (i = 0; i < num; i++, src++, dst++) + *dst = *src; + /* TODO: optimize for non non-trivially copyable types: */ + /*memmove(mData, mStart + this->size() - num, num * sizeof(complex)); */ return num; } -- To view, visit https://gerrit.osmocom.org/10721 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-trx Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: I9724454dfb7b87f74f39074e4004580ac3b5fe5c Gerrit-Change-Number: 10721 Gerrit-PatchSet: 3 Gerrit-Owner: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org> Gerrit-Reviewer: Jenkins Builder (1000002) Gerrit-Reviewer: Pau Espin Pedrol <pes...@sysmocom.de> Gerrit-CC: Vadim Yanitskiy <axilira...@gmail.com>