A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[mc] Avoid extra memory allocation and fix off-by-one buffer overflow
[simgrid.git]
/
src
/
mc
/
AddressSpace.hpp
diff --git
a/src/mc/AddressSpace.hpp
b/src/mc/AddressSpace.hpp
index
5c4f515
..
1fd9e49
100644
(file)
--- 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<char> address, std::size_t len) const
{
/** Read a string of known size */
std::string read_string(RemotePtr<char> address, std::size_t len) const
{
- // TODO, use std::vector with .data() in C++17 to avoid useless copies
- std::vector<char> 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;
}
};
}
};