aboutsummaryrefslogtreecommitdiff
path: root/fesvr/htif.cc
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2021-08-26 15:48:15 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2021-08-26 15:48:15 +0000
commitfc99a20295e86e4ce21d052e05fcabcc225dbbf0 (patch)
treef1830860afd9fc84e22c8416eef2f1b033e3f00c /fesvr/htif.cc
parent719e929e638b884b99de2a90dad6c2b47a643969 (diff)
downloadspike-fc99a20295e86e4ce21d052e05fcabcc225dbbf0.zip
spike-fc99a20295e86e4ce21d052e05fcabcc225dbbf0.tar.gz
spike-fc99a20295e86e4ce21d052e05fcabcc225dbbf0.tar.bz2
fesvr: replace use of `std::vector::operator[0]`
This replaces multiple uses of `std::vector::operator[]` where the parameter is a constant `0` with the use of C++11's `std::vector::data` method. This fixes the root cause of invalid memory accesses. `std::vector::operator[]` is an unchecked memory access, and when the buffers are zero-sized (that is the buffer container is empty) either due to a 0 padding in the case of elfloader or NULL parameters to syscalls where permitted, the unchecked access may cause an invalid memory access. The use of `std::vector::data` is permitted even in such a case, though the returned memory may not be dereferenced. The general usage of the returned pointer is to pass to `memif_t`, which is careful about 0-sized buffer accesses, and so passing the result of `std::vector::data` is safe. This is theoretically a better access pattern as it also avoids having the compiler to re-materialize the pointer from the de-referenced location.
Diffstat (limited to 'fesvr/htif.cc')
-rw-r--r--fesvr/htif.cc2
1 files changed, 1 insertions, 1 deletions
diff --git a/fesvr/htif.cc b/fesvr/htif.cc
index 1a9d0fc..234032b 100644
--- a/fesvr/htif.cc
+++ b/fesvr/htif.cc
@@ -169,7 +169,7 @@ void htif_t::stop()
if (!sig_file.empty() && sig_len) // print final torture test signature
{
std::vector<uint8_t> buf(sig_len);
- mem.read(sig_addr, sig_len, &buf[0]);
+ mem.read(sig_addr, sig_len, buf.data());
std::ofstream sigs(sig_file);
assert(sigs && "can't open signature file!");