aboutsummaryrefslogtreecommitdiff
path: root/spike_main/spike.cc
diff options
context:
space:
mode:
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>2018-01-09 01:00:55 +0100
committerAndrew Waterman <aswaterman@gmail.com>2018-01-08 16:00:55 -0800
commitfd0dbf46c3d9f8b005d35dfed79dbd4b4b0f974a (patch)
treebd9e835e7940e61dca514de8864dc59801102aa4 /spike_main/spike.cc
parent874e55888f23024899db93231d2b7c672fab33bb (diff)
downloadspike-fd0dbf46c3d9f8b005d35dfed79dbd4b4b0f974a.zip
spike-fd0dbf46c3d9f8b005d35dfed79dbd4b4b0f974a.tar.gz
spike-fd0dbf46c3d9f8b005d35dfed79dbd4b4b0f974a.tar.bz2
mem_t: Throw an error if zero-sized memory is requested (#168)
* mem_t: Throw an error if zero-sized memory is requested If for some reason the user requests a memory size of 0 megabytes, print a useful error message. * Check for overflow in memory size If the user passes in a large enough memory size (-m) that the size in bytes doesn't fit into size_t, catch this error in the make_mems function.
Diffstat (limited to 'spike_main/spike.cc')
-rw-r--r--spike_main/spike.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/spike_main/spike.cc b/spike_main/spike.cc
index 1205965..d3caa22 100644
--- a/spike_main/spike.cc
+++ b/spike_main/spike.cc
@@ -47,6 +47,8 @@ static std::vector<std::pair<reg_t, mem_t*>> make_mems(const char* arg)
auto mb = strtoull(arg, &p, 0);
if (*p == 0) {
reg_t size = reg_t(mb) << 20;
+ if (size != (size_t)size)
+ throw std::runtime_error("Size would overflow size_t");
return std::vector<std::pair<reg_t, mem_t*>>(1, std::make_pair(reg_t(DRAM_BASE), new mem_t(size)));
}