aboutsummaryrefslogtreecommitdiff
path: root/riscv/devices.h
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 /riscv/devices.h
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 'riscv/devices.h')
-rw-r--r--riscv/devices.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/riscv/devices.h b/riscv/devices.h
index e4df6c9..4e4d27f 100644
--- a/riscv/devices.h
+++ b/riscv/devices.h
@@ -41,6 +41,8 @@ class rom_device_t : public abstract_device_t {
class mem_t : public abstract_device_t {
public:
mem_t(size_t size) : len(size) {
+ if (!size)
+ throw std::runtime_error("zero bytes of target memory requested");
data = (char*)calloc(1, size);
if (!data)
throw std::runtime_error("couldn't allocate " + std::to_string(size) + " bytes of target memory");