From: Gabriel Corona Date: Mon, 18 Jul 2016 12:32:13 +0000 (+0200) Subject: [mc] Avoid extra memory allocation and fix off-by-one buffer overflow X-Git-Tag: v3_14~753 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0d8026e21b557c69dfdb23f8b6fddb6d277e28df [mc] Avoid extra memory allocation and fix off-by-one buffer overflow --- diff --git a/src/mc/AddressSpace.hpp b/src/mc/AddressSpace.hpp index 5c4f51529d..1fd9e4966d 100644 --- a/src/mc/AddressSpace.hpp +++ b/src/mc/AddressSpace.hpp @@ -160,11 +160,10 @@ public: /** Read a string of known size */ std::string read_string(RemotePtr address, std::size_t len) const { - // TODO, use std::vector with .data() in C++17 to avoid useless copies - std::vector buffer(len); - buffer[len] = '\0'; - this->read_bytes(buffer.data(), len, address); - return std::string(buffer.data(), buffer.size()); + std::string res; + res.resize(len); + this->read_bytes(&res[0], len, address); + return res; } };